简体   繁体   English

ASP.NET MVC调用方法

[英]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 {} 正在重新创建模型,因为控制器@using {}内的编辑框中接收包含数据的模型

In other words: 换一种说法:

  1. new Model
  2. Add some data&doMagic and go to my partial 添加一些数据&doMagic并转到我的部分
  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. 而且我在步骤3中@using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {}了问题,因为某些方法(我认为是因为@using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {} ),我丢失了在步骤2中添加的数据。

The question is: 问题是:

Is it true? 是真的吗 Can @using (Html.BeginForm()) {} re-create my model or should i add all code? 可以@using (Html.BeginForm()) {}重新创建我的模型,还是应该添加所有代码?

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)" /> 我已经尝试过: <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. 如果您使用诸如隐藏字段之类的机制将所有数据存储在页面上,则会使页面变得沉重。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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