我已经被困在这一点上一段时间了。表格很好,但没有验证。此外,当我点击提交时,我收到错误:“加载部分视图脚本时出错(文件:~/Views/MacroPartials/ApplicationFormStub.cshtml)”
我不太确定我哪里出错了,非常感谢您对正确方向的建议,以使表单验证并至少通过。
这是我的模型:
[MetadataType(typeof(ApplicationMetaData))]
public partial class Application { }
public class ApplicationMetaData
{
[DisplayName("Employer Name")]
[Required (ErrorMessage="Please Enter the Employer's Name")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public string EmployerName { get; set; }
[DisplayName("Supervisor Name")]
[Required (ErrorMessage="Please Enter the Supervisor's Name")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public string SupervisorName { get; set; }
[DisplayName("Supervisor Title")]
[Required (ErrorMessage="Please Enter the Supervisor's Title")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public string SupervisorTitle { get; set; }
[DisplayName("Employer Address")]
[Required (ErrorMessage="Please Enter the Employer's Address")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public string EmployerAddress { get; set; }
[DisplayName("Employer City")]
[Required (ErrorMessage="Please Enter the Employer's City")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public string EmployerCity { get; set; }
[DisplayName("Employer State")]
[Required (ErrorMessage="Please Enter the Employer's State")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public object EmployerState { get; set; }
[DisplayName("Employer Zip")]
[Required (ErrorMessage="Please Enter the Employer's Zip")]
[StringLength(50, ErrorMessage = "Only 50 Characters allowed")]
public string EmployerZip { get; set; }
[DisplayName("Employer Phone")]
[StringLength(10, ErrorMessage = "Only 10 Characters allowed")]
public string EmployerPhone { get; set; }
}
宏部分文件:
@Html.Action("ShowApplication", "ServicesSurface")
表面控制器:
[HttpGet]
[ActionName("ShowApplication")]
public ActionResult ShowApplication()
{
return PartialView("ServicesApplicationForm", new ApplicationMetaData());
}
[HttpPost]
[ValidateAntiForgeryToken]
[ActionName("ShowApplication")]
public ActionResult ShowApplication(ApplicationMetaData Model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
try
{
//Linq Data Entry
}
catch (Exception oe)
{
Response.Write(oe.Message);
Response.End();
}
//Send Email
return RedirectToAction(RedirectUrl);
}
看法:
@using Umbraco.Web
@using UmbracoProd.code
@model Umbraco.Services.ApplicationMetaData
<script src="@Url.Content("/../../scripts/libs/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("/../../scripts/libs/jquery/jquery.validate.min.js")" type="text/javascript"></script>
<link href="@Url.Content("/../../css/Services/form.css")" rel="stylesheet" type="text/css" />
@using (Html.BeginUmbracoForm("ShowApplication", "ServicesSurface"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="FormArea">
<fieldset>
<legend>Section One</legend>
<ul>
<li>
@Html.LabelFor(x => x.EmployerName)
@Html.TextBoxFor(x => x.EmployerName)
</li>
<li>
@Html.ValidationMessageFor(x => x.EmployerName)
</li>
<li>
@Html.LabelFor(x => x.SupervisorName)
@Html.TextBoxFor(x => x.SupervisorName)
</li>
<li>
@Html.ValidationMessageFor(x => x.SupervisorName)
</li>
<li>
@Html.LabelFor(x => x.SupervisorTitle)
@Html.TextBoxFor(x => x.SupervisorTitle)
</li>
<li>
@Html.ValidationMessageFor(x => x.SupervisorTitle)
</li>
<li>
@Html.LabelFor(x => x.EmployerAddress)
@Html.TextBoxFor(x => x.EmployerAddress)
</li>
<li>
@Html.ValidationMessageFor(x => x.EmployerAddress)
</li>
<li>
@Html.LabelFor(x => x.EmployerCity)
@Html.TextBoxFor(x => x.EmployerCity)
</li>
<li>
@Html.ValidationMessageFor(x => x.EmployerCity)
</li>
<li>
@Html.LabelFor(x => x.EmployerState)
@Html.StateDropDownList("EmployerState", "IN")
</li>
<li>
@Html.ValidationMessageFor(x => x.EmployerState)
</li>
<li>
@Html.LabelFor(x => x.EmployerZip)
@Html.TextBoxFor(x => x.EmployerZip)
</li>
<li>
@Html.ValidationMessageFor(x => x.EmployerZip)
</li>
<li>
@Html.LabelFor(x => x.EmployerPhone)
@Html.TextBoxFor(x => x.EmployerPhone)
</li>
<li>
@Html.ValidationMessageFor(x => x.EmployerPhone)
</li>
</ul>
</fieldset>
<input type="submit" class="button" value="Submit"/>
</div>
}