简体   繁体   中英

ASP.NET MVC calling a method

I need to pass already existing model into a method from my partial, the problem is that (it looks like) this syntax

@using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {}

is recreating my model, because my controller is receiving model with data only from edit-boxes inside @using {}

In other words:

  1. new Model
  2. Add some data&doMagic and go to my partial
  3. In my partial add more data and pass it to the controller
  4. Work with data

And i have the problem in step 3, because some how (i think because of @using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {} ) i am losing data added in step 2.

The question is:

Is it true? Can @using (Html.BeginForm()) {} re-create my model or should i add all code?

There is some other way to call a method and pass data there?

I have tried this : <input type="submit" onclick="@Html.Action("EmployeeOverallReportFilter", "Reports", Model)" />

But the error :

Exception Details: System.Web.HttpException: A public action method 'EmployeeOverallReportFilter' was not found on controller 'BTGHRM.Controllers.ReportsController'.

    [HttpPost]
    public ActionResult EmployeeOverallReportFilter(EmployeeOverallReport model)
    {
        //foreach(var item in model.ListOfPersonalData)
        //{
        //    //NameFiler
        //    if((!item.FirstName.Contains(model.ModelFilters.NameFilter)) && model.ModelFilters.NameFilter!=String.Empty) model.ListOfPersonalData.Remove(item);
        //}
        return View("EmployeeOverAllReport", model);
    }

I would suggest create a session and store the existing Model and then equate the new changes into the existing model from the session. If you store all your data on the page using a mechanism like hidden fields it will make your page heavy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM