Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot re-submit a partial view that have modelState errors using firefox and chrome
    primarykey
    data
    text
    <p>I have defined the following data annotation on my model class:-</p> <pre><code>[Display(Name = "Lab Test Description")] [Required] public int LabTestID { get; set; } [Display(Name = "Test Result")] [Range(typeof(decimal), "0.00", "9999999999.9999999999")] [Required] public decimal Result { get; set; } </code></pre> <p>Then on the view i have defined the following, to display 10 create forms inside a table:-</p> <pre><code>@model Medical.Models.VisitLabResult &lt;table&gt; &lt;tr&gt; &lt;th&gt; Lab Test &lt;/th&gt; &lt;th&gt; Result &lt;/th&gt; &lt;th&gt; Date Taken &lt;/th&gt; &lt;th&gt; Comment &lt;/th&gt; &lt;th&gt; &lt;/th&gt; &lt;/tr&gt; @for (int item = 0; item &lt; 10; item++) { using (Ajax.BeginForm("CreateAll", "VisitLabResult", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = item.ToString(), InsertionMode = InsertionMode.Replace })) { &lt;tr id = "@item"&gt; @Html.ValidationSummary(true) @Html.AntiForgeryToken() &lt;td&gt; @Html.DropDownList("LabTestID", String.Empty) @Html.ValidationMessageFor(model =&gt; model.LabTestID) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(model =&gt; model.Result) @Html.ValidationMessageFor(model =&gt; model.Result) &lt;/td&gt; &lt;td&gt; @Html.TextBox("DateTaken", null, new { @id = "DateTaken" + item.ToString(), DataFormatString = "{0:D}" , ApplyFormatInEditMode = true }) @Html.ValidationMessageFor(model =&gt; model.DateTaken) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(model =&gt; model.Comment) @Html.ValidationMessageFor(model =&gt; model.Comment) &lt;/td&gt; &lt;td&gt; @Html.HiddenFor(model =&gt; model.VisitID) &lt;input type="submit" value="Create" /&gt; &lt;/td&gt; &lt;/tr&gt; } } &lt;/table&gt; &lt;div&gt; @Html.ActionLink("Back To Current Visit", "Edit", "Visit", new { id = Model.VisitID }, null) &lt;/div&gt; </code></pre> <p>The above 10 <code>Beginforms</code> will call the following action method separately :-</p> <pre><code>[HttpPost] [ValidateAntiForgeryToken] public ActionResult CreateAll(VisitLabResult vlr) { try { if (ModelState.IsValid) { repository.AddVisitLabResult(vlr); repository.Save(); string message = repository.checkrange(vlr.LabTestID,vlr.VisitID); var lab = repository.GetLabTest(vlr.LabTestID,false); ViewBag.status = message; return PartialView("_create",vlr) ;} } catch (DbUpdateException) { ViewBag.LabTestID = new SelectList(repository.FindAllLabTest(), "LabTestID", "Description", vlr.LabTestID); ModelState.AddModelError("LabTestID", "The Same test Type might have been already created,, go back to the Visit page to see the avilalbe Lab Tests"); ViewBag.status = "Error"; return PartialView("_createToedit", vlr); } ViewBag.LabTestID = new SelectList(repository.FindAllLabTest(), "LabTestID", "Description", vlr.LabTestID); ViewBag.status = "Error"; return PartialView("_createToedit", vlr); } </code></pre> <p>As shown in the above code,the action method will return "_create” partial view if case the action was performed successfully. While it will return the “_createToedit” partial view - incase of any error- which looks as follow:-</p> <pre><code>&lt;td&gt; @Html.ValidationSummary(true) @Html.AntiForgeryToken() @Html.DropDownList("LabTestID", String.Empty) @Html.ValidationMessageFor(model =&gt; model.LabTestID) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(model =&gt; model.Result) @Html.ValidationMessageFor(model =&gt; model.Result) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(model =&gt; model.DateTaken) @Html.ValidationMessageFor(model =&gt; model.DateTaken) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(model =&gt; model.Comment) @Html.ValidationMessageFor(model =&gt; model.Comment) &lt;/td&gt; &lt;td&gt; @Html.HiddenFor(model =&gt; model.VisitID) &lt;input type="submit" value="Create" /&gt; &lt;/td&gt; </code></pre> <p>But currently i am facing the following two problems with the above code:-</p> <p><strong>1.</strong> when I access the system using fireFox or chrome browsers the user will not be able to re-submit the “_createToedit” partial view which will contain the ModelState errors and any data annotation errors. And if the users clicks on the “Create” button then nothing will happen (the view will keep displaying the same error/s and the same fields!!!). While the user will be able to re-submit the partial view using internet explorer 9 without any problems.</p> <p><strong>2.</strong> Second problem is that all the data annotations validation such as [Required] will not be displayed unless the user click on the “Create” button, although i have enabled client-side validation inside my application(and the client side validation is working well on other views) . Where this problem is happening on all the browsers (IE9,firefox &amp; chrome).</p> <p>So can anyone help me in finding what is wrong in my code that is raising the above two problems.* Thanks in advance for any help. BR</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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