Reputation: 422
I have a modal popup, but I want to do model state validations on it. The problem is that if there is a model state error it returns the page. How do I return the data to the popup, keeping the popup open. Here is what I have so far:
[HttpPost]
public ActionResult SaveProject( AddstuffViewModel model )
{
if (!ModelState.IsValid)
{
return PartialView("_Addstuff", model);
}
}
@model Models.AddStuffViewModel
@using (Ajax.BeginForm(
"SaveProject", "Projects",
new AjaxOptions {
HttpMethod = "POST",
},
new {
id = "FormName",
role = "form" }
))
{
<div class="panel-heading projectModal-heading">
<h4 class="panel-title">Add stuff </h4>
</div>
<div class="panel-body">
<p class="group">
<div class="form-group">
@Html.LabelFor(m => m. Stuffs.Name, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Stuffs.Name, new { @class = "form-control", @id = "InputName", @placeholder = "Stuffs Name" })
@Html.ValidationMessageFor(m => m.Stuffs.Name, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Stuffs.Description, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Stuffs.Description, new { @class = "form-control", @id = "InputDescription", @placeholder = "Description" })
@Html.ValidationMessageFor(m => m.Stuffs.Description, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Stuffs.Url, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Stuffs.Url, new { @class = "form-control", @id = "InputUrl", @placeholder = "Url" })
@Html.ValidationMessageFor(m => m.Stuffs.Url, "", new { @class = "text-danger" })
</div>
</div>
</p>
</div>
<div class="panel-footer">
<input type="submit" value="stuff" class="btn btn-default" />
</div>
}
The modal opens fine and all the data gets populated correctly. I just want to keep it open when the SaveProject method returns.
Upvotes: 4
Views: 3626
Reputation: 422
Hate answering my own Question, but I had an id-10-T error.
I included jquery.validate.unobtrusive instead of jquery.unobtrusive-ajax originally. I included both now it works fine.
Upvotes: 2