我正在开发一个asp.net MVC应用程序,在渲染Html.BeginForm()之后我遇到了一个奇怪的错误。
代码:
@using (Html.BeginForm("ValidateData", "Assurity", FormMethod.Post, new { @class = "form-horizontal" }))
{
<div class="form-group">
@Html.LabelFor(m => m.FirstName, new { @for = "firstName", @class = "label_16 col-sm-2 control-label" })
<div class="col-sm-6">
@Html.TextBoxFor(m => m.FirstName, new { @class = "form-control input-lg label_16", @placeholder = @Resources.PSI.FirstNamePlaceHolder })
@Html.ValidationMessageFor(m => m.FirstName, null, new { @class = "label_16" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Surname, new { @for = "Surname", @class = "label_16 col-sm-2 control-label" })
<div class="col-sm-6">
@Html.TextBoxFor(m => m.Surname, new { @class = "form-control input-lg label_16", @placeholder = @Resources.PSI.SurnamePlaceHolder })
@Html.ValidationMessageFor(m => m.Surname, null, new { @class = "label_16" })
</div>
</div>
<div class="spacer_30 clearfix hidden-xs"></div>
<div class="spacer_10 clearfix visible-xs"></div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8 text-right">
<button type="submit" class="btn btn-default btn-xlg btn-responsive label_18 label_900_White_shadow" >CONFIRM</button>
</div>
</div>
}
它呈现一个像:
的html<form action="/" class="form-horizontal" method="post"> <div class="form-group">
<label class="label_16 col-sm-2 control-label" for="firstName">First Name</label>
<div class="col-sm-6">
<input class="form-control input-lg label_16" data-val="true" data-val-required="The First Name field is required." id="FirstName" name="FirstName" placeholder="Enter here your first name" type="text" value="">
<span class="field-validation-valid label_16" data-valmsg-for="FirstName" data-valmsg-replace="true"></span>
</div>
</div>
<div class="form-group">
<label class="label_16 col-sm-2 control-label" for="Surname">Surname</label>
<div class="col-sm-6">
<input class="form-control input-lg label_16" data-val="true" data-val-required="The Surname field is required." id="Surname" name="Surname" placeholder="Enter here your surname" type="text" value="">
<span class="field-validation-valid label_16" data-valmsg-for="Surname" data-valmsg-replace="true"></span>
</div>
</div>
<div class="spacer_30 clearfix hidden-xs"></div>
<div class="spacer_10 clearfix visible-xs"></div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8 text-right">
<button type="submit" class="btn btn-default btn-xlg btn-responsive label_18 label_900_White_shadow">CONFIRM</button>
</div>
</div>
</form>
那么,为什么没有控制器和动作名称渲染表单?这段代码有什么问题?
更新:
public virtual ActionResult ValidateData()
{
return View(MVC.Assurity.Views.DefaultPSI, new PSIViewModel());
}
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public virtual async Task<ActionResult> ValidateData(PSIViewModel vm)
{
路线:
routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}", defaults:
new
{
controller = MVC.Assurity.Name,
action = MVC.Assurity.ActionNames.ValidateData,
id = UrlParameter.Optional
});