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:
換一種說法:
new Model
添加一些數據和doMagic並轉到我的部分
在我的部分添加更多數據並將其傳遞給控制器
處理數據
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);
}
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.
我建議創建一個會話並存儲現有的模型,然后將新的更改等同於會話中的現有模型。如果使用隱藏字段等機制將所有數據存儲在頁面上,則會使頁面變重。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/10/03/72011ba465feaa02943b785d7ed6e926.html。