Note that there are some explanatory texts on larger screens.

plurals
  1. POModelState in MVC does not show the error
    primarykey
    data
    text
    <p>in my controller i have Create action for view .i want to show validation exception with ModelState .but it does not work truly.</p> <pre><code> /// &lt;summary&gt; /// GET: /AgentPosition/Create /// &lt;/summary&gt; /// &lt;param name="model"&gt;The model.&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public override ActionResult Create(Models.AgentPosition.AgentPositionModel model) { if (model.PositionContacts == null || model.BankAccountDetails == null) { if (model.PositionContacts == null) { this.ModelState.AddModelError("PositionContacts",Resources.Resource.MustInputPositionContact); } if (model.BankAccountDetails == null) { this.ModelState.AddModelError("BankAccounts", Resources.Resource.MustInputBankAccountDetail); } return this.View(model); } return base.Create(model); } </code></pre> <p>in My View </p> <pre><code> @using (this.Html.BeginForm("Create", "AgentPosition", FormMethod.Post, new { enctype = "multipart/form-data" })) { this.Html.ValidationSummary(true); &lt;div&gt; @this.Html.Partial("BankAccounts", this.Model) @this.Html.ValidationMessageFor(model =&gt; model.BankAccountDetails) &lt;/div&gt; &lt;div&gt; @this.Html.Partial("PositionContacts", this.Model) @this.Html.ValidationMessageFor(model =&gt; model.PositionContacts) &lt;/div&gt; </code></pre> <p>}</p> <p>I give only one Exception Validation from ModelState(First Model Error) in View.</p> <p>I find the answer. I must change this code :</p> <pre><code>this.ModelState.AddModelError("BankAccounts", Resources.Resource.MustInputBankAccountDetail); </code></pre> <p>TO </p> <pre><code>this.ModelState.AddModelError("BankAccountDetails", Resources.Resource.MustInputBankAccountDetail) </code></pre> <p>because in MVC we must have same PropertyName in Model and it in dictionary that save exception in modelstate. </p>
    singulars
    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