Note that there are some explanatory texts on larger screens.

plurals
  1. POValidation firing for both controls
    primarykey
    data
    text
    <p>I currently have two partial views on a single page, added with:</p> <pre><code>@Html.Action("_LogonBox","Account") @Html.Action("_TrackingBox","Tracking") </code></pre> <p>each has its own form and model...</p> <p>but if I enter values into the _logonbox view and submit it it causes the validation to fire on the TrackingBox and because the values in tracking box are empty it highlights the textboxes as errors.</p> <p>How do I sort this out, in webforms it was simply validationGroups?</p> <p><strong>EDIT</strong></p> <p>here is the markup:</p> <p><strong>LogOn View</strong></p> <pre><code> @model Models.LogonModel @using (Html.BeginForm("Login", "account", FormMethod.Post, new { Id = "Login" })) { &lt;div class="boxwrapper"&gt; &lt;div class="loginbox"&gt; &lt;a href="#" style="float: right; color: #fff; font-size: 95%%; padding: 5px 10px;"&gt;Forgotten Password?&lt;/a&gt; &lt;h3&gt; My Account&lt;/h3&gt; &lt;div class="content"&gt; &lt;fieldset class="logincontrols"&gt; &lt;table&gt; &lt;tr&gt; &lt;td class="loginlabel"&gt; @Html.LabelFor(m =&gt; m.UserName) &lt;/td&gt; &lt;td class="logintextbox"&gt; @Html.TextBoxFor(m =&gt; m.UserName, new { ValidationGroup = "Account" }) &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="loginlabel"&gt; @Html.LabelFor(m =&gt; m.Password) &lt;/td&gt; &lt;td class="logintextbox"&gt; @Html.PasswordFor(m =&gt; m.Password, new { ValidationGroup = "Account" })&amp;nbsp; &lt;input type="image" value="Sign In" src="/Content/Images/buttons/signin.png" style="vertical-align: bottom;" ValidationGroup="Account" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;} </code></pre> <p><strong>Tracking View</strong></p> <pre><code>@model .Models.TrackingModel @using (Html.BeginForm("Index", "Tracking", new { Id = "Tracking" })) { &lt;div class="boxwrapper"&gt; &lt;div class="bluebox"&gt; &lt;fieldset class="logincontrols"&gt; &lt;h3&gt; Shipment Tracking&lt;/h3&gt; &lt;div class="content"&gt; &lt;p style="text-align: left;"&gt; &amp;nbsp; &amp;nbsp;Please enter your reference number:&lt;/p&gt; @Html.TextBoxFor(m =&gt; m.TrackingNumber) &lt;br /&gt; &lt;p style="text-align: right; margin-top: 10px;"&gt; &lt;input type="image" value="Track Shipment" src="/Content/Images/buttons/trackingbutton.png" /&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt; &lt;/div&gt; &lt;fieldset&gt; &lt;/div&gt; &lt;/div&gt; } </code></pre> <p><strong>Further EDIT</strong> <em>added controllers as requested</em></p> <pre><code> public class TrackingController : Controller { // // GET: /Tracking/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(TrackingModel model) { return View(model); } [HttpPost] public PartialViewResult _TrackingBox(TrackingModel model) { return PartialView(model); } public PartialViewResult _TrackingBox() { return PartialView(); } } public class AccountController : Controller { public ActionResult Login() { return View(); } [HttpPost] public ActionResult Login(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, false); if (Url.IsLocalUrl(returnUrl) &amp;&amp; returnUrl.Length &gt; 1 &amp;&amp; returnUrl.StartsWith("/") &amp;&amp; !returnUrl.StartsWith("//") &amp;&amp; !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); } public PartialViewResult _Logonbox() { return PartialView(); } [HttpPost] public PartialViewResult _Logonbox(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { //do something here } // If we got this far, something failed, redisplay form return PartialView(model); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload