Ich bin neu in ASP.NET MVC und mit Version 5. Ich habe ein Formular erstellt, das im Layout ist, und ich kann nicht erhalten Validierungsfehler auf der Ansicht zu zeigen. Es wird korrekt an die Aktion gesendet, und wenn das Modell gültig ist, wird es ausgeführt. Wenn das Modell ungültig ist, erhalte ich den folgenden Fehler.ASP.NET MVC 5 Form Validierung
Ich hoffe, dass jemand mich in die richtige Richtung zeigen kann. Vielen Dank im Voraus!
Server Error in '/' Application.
The view 'ContactSubmit' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/ContactSubmit.aspx
~/Views/Home/ContactSubmit.ascx
~/Views/Shared/ContactSubmit.aspx
~/Views/Shared/ContactSubmit.ascx
~/Views/Home/ContactSubmit.cshtml
~/Views/Home/ContactSubmit.vbhtml
~/Views/Shared/ContactSubmit.cshtml
~/Views/Shared/ContactSubmit.vbhtml
Das ist mein Modell verwende ich:
public partial class Lead
{
[Key]
public int LeadId { get; set; }
[Required]
[StringLength(50, MinimumLength=2, ErrorMessage="* A valid first name is required.")]
[Display(Name="First Name")]
public string FirstName { get; set; }
[Required]
[StringLength(50, MinimumLength=2, ErrorMessage="* A valid last name is required.")]
[Display(Name="Last Name")]
public string LastName { get; set; }
[Required]
[StringLength(50, MinimumLength=2, ErrorMessage="* A valid company is required.")]
public string Company { get; set; }
[Required]
[StringLength(50)]
[EmailAddress(ErrorMessage="* A valid email address is required.")]
public string Email { get; set; }
[Required]
[StringLength(15, MinimumLength=9, ErrorMessage="* A valid phone nunber is required.")]
[Phone(ErrorMessage="Please enter a valid phone number.")]
public string Phone { get; set; }
}
Dies ist der Code, den ich in meiner Heimsteuerung habe:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ContactSubmit(
[Bind(Include = "FirstName, LastName, Company, Email, Phone")]
Lead lead)
{
try
{
if (ModelState.IsValid)
{
lead.Tenant = SessionManager.Get<Tenant>(Constants.SessionTenant);
lead.Refferer = SessionManager.Get<string>(Constants.SessionRefferal);
DataStoreManager.AddLead(lead);
return RedirectToAction("SubmissionConfirmed", lead);
}
}
catch (DataException /* dex */)
{
ModelState.AddModelError("", "Unable to perform action. Please contact us.");
return RedirectToAction("SubmissionFailed", lead);
}
return View(lead);
}
[HttpGet]
public ActionResult ContactSubmit()
{
return View();
}
Dies ist die Form, die ich in meinem Layout :
@using (Html.BeginForm("ContactSubmit", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
<fieldset>
<div class="editor-label">
@Html.LabelFor(m => m.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.FirstName)
@Html.ValidationMessageFor(m => m.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.LastName)
@Html.ValidationMessageFor(m => m.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Company)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.Company)
@Html.ValidationMessageFor(m => m.Company)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Email)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.Email)
@Html.ValidationMessageFor(m => m.Email)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Phone)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.Phone)
@Html.ValidationMessageFor(m => m.Phone)
</div>
<div class="masthead-button-wrapper">
<input class="btn btn-warning" type="submit" value="Submit" />
</div>
</fieldset>
}
Wie lautet der Dateiname Ihrer 'Ansicht'? –