0
值這是由Visual Studio生成時,我添加了一個視圖我的編輯功能我如何通過從html.editorfor()到我的控制器
我想通過生成的<input>
內的值的代碼由@Html.EditorFor()
從視圖到我的控制器。
我如何訪問這些值?我可以通過<input class="form-control text-box single-line" id="Surname" name="Surname" type="text">
手動聲明文本框嗎?
@using (Html.BeginForm("Save","my",FormMethod.Post)){
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>User</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @Value=Model.Name, @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
你不需要'[Bind]'屬性(默認包含所有屬性) –