繁体   English   中英

ASP.NET MVC调用方法

[英]ASP.NET MVC calling a method

我需要将已经存在的模型从我的部分传递到方法中,问题是(看起来像)这种语法

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

正在重新创建模型,因为控制器@using {}内的编辑框中接收包含数据的模型

换一种说法:

  1. new Model
  2. 添加一些数据&doMagic并转到我的部分
  3. 在我的部分中,添加更多数据并将其传递给控制器
  4. 处理数据

而且我在步骤3中@using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {}了问题,因为某些方法(我认为是因为@using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {} ),我丢失了在步骤2中添加的数据。

问题是:

是真的吗 可以@using (Html.BeginForm()) {}重新创建我的模型,还是应该添加所有代码?

还有其他方法可以调用方法并在那里传递数据吗?

我已经尝试过: <input type="submit" onclick="@Html.Action("EmployeeOverallReportFilter", "Reports", Model)" />

但是错误:

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

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

暂无
暂无

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

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