0

I am using ExcelReader to upload new sheet of containing data and get all old data from the DbSet.I am using Entity Framework POCO way to POST/GET data. I want to use same view for both POST/GET.I have two submit button one for saving current data and one for get all data from datacontext.Now my View Code is below I followed the steps included here! I getting following error "System.Reflection.AmbiguousMatchException". I am guessing this because of HTNL.Beginfrom() creating it because of action result name. Can any one help me how to resolve this issue if I need to use @Html.AntiForgeryToken(); @Html.ValidationSummary(); in my both the GET/POST call.

    [MultipleButton(Name = "action", Argument = "Index")]
    public ActionResult Index(HttpPostedFileBase uploadfile,dataViewModel dataView1)
    {
      // code for upload
     }  

    [MultipleButton(Name = "action", Argument = "ExcelData")]
    public ActionResult ExcelData()
    {
     ReadContext Context = new ReadContext();   
     return View(Context.dataext.ToList());
    }

My View code:

@{
ViewBag.Title = "Read Excel File and Display in mvc5";
}
@model System.Data.DataTable
@using System.Data

<h2>Read Excel File and Display in mvc5</h2>
@using (Html.BeginForm("Index", "ReadExcel", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken();
    @Html.ValidationSummary();

    <label class="text-info">Upload Excel File</label>
    <input type="file" class="form-control" name="uploadfile" id="uploadfile" />
    <input type="submit" value="submit" class="btn btn-default" name="action:Index" />
    <input type="submit" value="data" class="btn btn-default" name="action:ExcelData" />            

    if (Model != null)
    {
        <table class="table table-responsive table-bordered">
            <thead>
                <tr>
                    @foreach(DataColumn column in Model.Columns)
                    {
                        <th>@column.ColumnName</th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach(DataRow row in Model.Rows)
                {
                    <tr>

                        @foreach(DataColumn col in Model.Columns)
                        {

                            <td>@row[col.ColumnName]</td>
                        }
                    </tr>
                }
            </tbody>
        </table>
    }
}
dipc
  • 1
  • 4
  • Try marking `Index` action with `HttpPostAttribute` as in example: `[HttpPost][MultipleButton(Name = "action", Argument = "Index")] public ActionResult Index(...) { ... }`, or change `Index` action name with anything else (since `Index` used for default first action when every controller requested by URL). – Tetsuya Yamamoto Nov 03 '17 at 06:21
  • already had [HttpPost] also changed name index to public ActionResult excel{..} but no change in error name – dipc Nov 03 '17 at 07:11

0 Answers0