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)) {}

@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
  3. 添加一些数据和doMagic并转到我的部分

  4. In my partial add more data and pass it to the controller
  5. 在我的部分添加更多数据并将其传递给控制器

  6. Work with data
  7. 处理数据

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)){})我丢失了第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)" />

我试图这样:

But the error :

但错误:

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

异常详细信息:System.Web.HttpException:在控制器“BTGHRM.Controllers.ReportsController”上找不到公共操作方法“EmployeeOverallReportFilter”。

    [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);
    }

1 个解决方案

#1


2  

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.

我建议创建一个会话并存储现有的模型,然后将新的更改等同于会话中的现有模型。如果使用隐藏字段等机制将所有数据存储在页面上,则会使页面变重。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2016/10/03/72011ba465feaa02943b785d7ed6e926.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告