如何從foreach循環中的TextBoxFor
幫助程序中檢索數據?我的意思是:在foreach循環中的c#razor mvc textboxfor
:
foreach(Language l in ViewBag.Languages){
<td>@l.lang</td>
<td>@Html.TextBoxFor(model => model.Name)
}
,我該如何找回它在控制器一次貼?
MyModel.Name //this returns the value of the first textbox within the foreach loop
通過model.Name在MyModel.cs定義方式:
public string Name { get; set; }
如果我將模型作爲參數傳遞,該怎麼辦?我的意思是,如果控制器是這樣的:public ActionResult(MyModel model),我從模型中獲取值? – Shaokan
只要你有'string [] Name {get;組; }'對你的模型,默認的ModelBinder仍然能夠綁定到它。 – aligray