I am developing application which has Index.cshtml (main pg with searching criteria & Search button), _PartialView.cshtml (partial view displaying records with update/delete links), Edit.cshtml (View for updating).
After clicking Update link, popup modal dialog is opened containing Edit view (Edit.cshtml) I applied Required & StringLength attribute to some fields. If some of attributes not fulfilled, i want to display them in same popup. But in controller action method, I am returning View so modal popup disappears & Edit view is opened in div.
My records are displayed as grid in partialView (_PartialView.cshtml) with Update link and javascript function as
<a href="javascript:void(0);" class="anchorDetail" onclick="editFunc(@item.SrNo)" ">Update</a>
function editFunc(id) {
var TeamDetailPostBackURL = '/Home/Edit';
var $buttonClicked = $(this);
var options = { "backdrop": "static", keyboard: true };
$.ajax({
type: "GET",
url: TeamDetailPostBackURL,
cache: false,
contentType: "application/json; charset=utf-8",
data: { "SrNo": id },
datatype: "json",
success: function (data) {
$('#myModalContent').html(data);
$('#myModal').css('display', 'block');
$("#myModal").dialog({
title: 'Edit Data',
modal: true,
bgiframe: true,
show: 'slide',
hide: 'slide',
width: 750
});
$('#myModal').dialog("show");
},
error: function () {
alert("Dynamic content load failed.");
}
});
}
My Edit.cshtml :
@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { UpdateTargetId = "divPartial", HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnBegin = "CallEditBegin", OnSuccess = "CallUnblock" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label" style="display:none" >
@Html.LabelFor(model => model.SrNo)
</div>
<div class="editor-field" style="display:none">
@Html.EditorFor(model => model.SrNo)
@Html.ValidationMessageFor(model => model.SrNo)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReaderName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReaderName)
@Html.ValidationMessageFor(model => model.ReaderName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UploadDate)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.UploadDate, new { @readonly = "readonly" })
@Html.ValidationMessageFor(model => model.UploadDate)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
My HomeController.cs
[HttpPost]
public ActionResult Edit(UploadData uploadData)
{
if (!ModelState.IsValid)
{
return View(uploadData);
}
else
{
string strResult = uploadDataBusinessLayer.InsertUpdateUploadData(uploadData, "Update");
if (strResult == "Success")
{
}
else
{
}
}
}
Now some filed are required and ReaderName has restiction of min length of 6 characters. If any of the condition not fulfilled
if (!ModelState.IsValid)
{
return View(uploadData);
}
this block will be executed.
But what happened next, my popup dialog disappears & div will be open on main pg displaying error message.
I want to show them on popup itself in front of control.
I am confusing what to do in case of model errors.
Please give some advice, what I am missing.....
What I have tried:
Searched on google but cant find any suitable information.......