Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery string param is missed when form validation fail
    text
    copied!<p>I have an form with following url: CreateEntity?<strong>officeCodeId=5</strong></p> <p>When I send form to validate and if validation is fail it returns just CreateEntity url. No officeCodeId=5.</p> <p>if user click enter on URL or F5 - my site fail - it require missing officecodeId param. I can save it to the session or in the other storage. But I want to have it in the URL</p> <p>My view:</p> <pre><code>[HttpGet] public virtual ActionResult CreateEntity(int? officeCodeId) { var model = new CreateViewModel(); FillViewModel(model, officeCodeId); return View("Create", model); } [HttpPost] protected virtual ActionResult CreateEntity(TEditViewModel model) { if (ModelState.IsValid) { //Do some model stuff if } return View("Create", model); } </code></pre> <p>EDIT. My View:</p> <pre><code>using (Html.BeginForm("CreateEntity", "Employee", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.HiddenFor(x =&gt; x.OfficeCodeId) &lt;div&gt; @Html.LabelFor(model =&gt; model.FirstName, CommonRes.FirstNameCol) @Html.TextBoxFor(model =&gt; model.FirstName, Model.FirstName) @Html.ValidationMessageFor(model =&gt; model.FirstName) &lt;/div&gt; &lt;div&gt; @Html.LabelFor(model =&gt; model.LastName, CommonRes.LastNameCol) @Html.TextBoxFor(model =&gt; model.LastName, Model.LastName) @Html.ValidationMessageFor(model =&gt; model.LastName) &lt;/div&gt; &lt;div&gt; &lt;div class="input-file-area"&gt;&lt;/div&gt; &lt;input id="Agreements" type="file" name="Agreements"/&gt; &lt;/div&gt; </code></pre> <p>}</p> <p>Edit 2. Adding: </p> <pre><code>@using (Html.BeginForm("CreateEntity", "Employee", FormMethod.Post, new { officeCodeId = Model.OfficeCodeId, enctype = "multipart/form-data" })) </code></pre> <p>Haven`t help. It produce the following form:</p> <pre><code>&lt;form action="/PhoneEmployee/CreateEntity" enctype="multipart/form-data" method="post" officecodeid="5"&gt; </code></pre> <h2>Solution Is</h2> <pre><code>&lt;form action="@Url.Action("CreateEntity", "Employee")?officecodeid=@Model.OfficeCodeId" enctype="multipart/form-data" method="post"&gt; </code></pre>
 

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