i have the following action method, that returns a partial view _create
. but is there a way to pass a Json object such as return Json(new { IsSuccess = "True" },
with the Partial view.
My Action method looks as follow:-
try
{
if (ModelState.IsValid)
{
var v = repository.GetVisit(visitid);
if (!(v.EligableToStart(User.Identity.Name)))
{
return View("NotFound");
}
vlr.VisitID = visitid;
repository.AddVisitLabResult(vlr);
repository.Save();
ViewBag.LabTestID = new SelectList(repository.FindAllLabTest(), "LabTestID", "Description", vlr.LabTestID);
// return Json(new { IsSuccess = "True" }, JsonRequestBehavior.AllowGet);
@ViewBag.status = "Added Succsfully";
return PartialView("_create",vlr) ;
}
}
::-UPDATED-::
what i am trying to do as follow:-
i am calling the action method using ajax.beginform
using (Ajax.BeginForm("CreateAll", "VisitLabResult", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = item.ToString(), InsertionMode = InsertionMode.Replace, OnSuccess = string.Format("disableform({0})", Json.Encode(item)), }))
after successfully receiving the response from the server ,, the Onsuccess script will be executed,,, the script simply disable the form:-
function disableform(id) { $('#' + id + ' :input').prop("disabled", true); }
The problem is that the script will always disable the form even is some validation error occurs,, so what i was trying to achieve is to return a JSON with the partial view that indicate if the ModelState.IsValid was valid or not,, and if it was not valid to keep the form enabled to allow the user to correct the validation errors.
BR