[英]ASP.NET MVC calling a method
我需要將已經存在的模型從我的部分傳遞到方法中,問題是(看起來像)這種語法
@using (Html.BeginForm("EmployeeOverallReportFilter", "Reports", FormMethod.Post)) {}
正在重新創建模型,因為控制器@using {}
內的編輯框中接收包含數據的模型
換一種說法:
new Model
而且我在步驟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.