Note that there are some explanatory texts on larger screens.

plurals
  1. POAlert Javascript as return response of action
    text
    copied!<p>how can i do, for example, i create a user in users.cshtml view, that it validates to ActionResult Create(RegisterModel um) and if its all ok, i want to return at users.cshtml but always with one javascript alert or similar, with the value of a variable from the action. Can i do this one?</p> <p>I have it this in my view..</p> <pre><code>@using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Crear Usuario&lt;/legend&gt; &lt;div class="editor-label"&gt; Username: &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.UserName) @Html.ValidationMessageFor(model =&gt; model.UserName) &lt;/div&gt; &lt;div class="editor-label"&gt; Password: &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.PasswordFor(model =&gt; model.Password) @Html.ValidationMessageFor(model =&gt; model.Password) &lt;/div&gt; &lt;div class="editor-label"&gt; Repite Password: &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.PasswordFor(model =&gt; model.ConfirmPassword) @Html.ValidationMessageFor(model =&gt; model.ConfirmPassword) &lt;/div&gt; &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Crear" /&gt; &lt;/p&gt; &lt;/fieldset&gt; </code></pre> <p>And this in my controller action..</p> <pre><code>public ActionResult Create(RegisterModel um) { if (um.Password == um.ConfirmPassword) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(um.UserName, um.Password, um.Email, um.PasswordAnswer, um.PasswordQuestion, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { var alert = MembershipCreateStatus.Success.ToString(); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); var alert = ErrorCodeToString(createStatus); } } //HERE IS WHERE I WANT TO RETURN TO /ADMIN/USERS BUT WITH AN ALERT WITH CONTAINING THE VALUE OF alert IN A JAVASCRIPT OR SIMILAR ALERT WINDOW return RedirectToAction("Users", "Admin"); ??????? </code></pre> <p>Can i do it something like this?</p>
 

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