传回表单时,我的电阻器工作得很好,但是我构建的电阻器没有传回任何东西。我不确定我在做什么与 Visual Studio 提供的注册页面不同。它调用正确的 http post 方法,但传递的值为 null。谢谢你的帮助。我只是希望该模型回发到控制器操作结果。
控制器
[HttpGet]
public ActionResult Support()
{
ViewBag.Message = "Your app description page.";
return View();
}
[AllowAnonymous]
[HttpPost, ValidateSpamPrevention]
public ActionResult Support(QuickEmailModel email)
{
if (ModelState.IsValid)
{
return View("thankyou", email);
}
return View(email);
}
模型
public class QuickEmailModel
{
[DataType(DataType.EmailAddress)]
[EmailAddress]
public string Email { get; set; }
[Required]
public string Subject { get; set; }
[Required]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
[Display(Name = "Company (Optional):")]
public string Company { get; set; }
}
}
视图顶部
@using PoliteCaptcha
@model Models.QuickEmailModel
@{
ViewBag.Title = "Support";
}
表格所在的底部
@using (Html.BeginForm())
{
@Html.ValidationSummary()
<div class="control-group">
<label class="control-label">
@Html.LabelFor(x => x.Company, "Company (Optional):", new { @class = "control-label" })</label>
<div class="controls">
@Html.TextBoxFor(x => x.Company, new { @class = "span4" })
</div>
</div>
<div class="control-group">
@Html.LabelFor(x => x.Email, "Email:", new { @class = "control-label" })
<div class="controls">
@Html.TextBoxFor(x => x.Email, new { @Class = "span4" })
</div>
</div>
<div class="control-group">
<label class="control-label">
@Html.LabelFor(x => x.Subject, "Subject:", new { @class = "control-label" })</label>
<div class="controls">
@Html.TextBoxFor(x => x.Subject, new { @class = "span4" })
</div>
</div>
<div class="control-group">
<label class="control-label">
@Html.LabelFor(x => x.Subject, "Description:", new { @class = "control-label" })</label>
<div class="controls">
@Html.TextAreaFor(x => x.Description, new { @class = "span4", @rows = "6", id = "txtDescription" })
</div>
</div>
@Html.SpamPreventionFields()
<input type="submit" class="btn btn-success" id="btnSubmit" value="Submit" style="margin-right: 15em;
float: right;" />
}