HTML
On your button click, you can declare the Action and it's corresponding Controller information in HTML. you can also set it hidden.
<div id="MyDiv" Control-Url = "@Url.Action("ActionName", "ControllerName")"
Action-Url = "@Url.Action("ActionName", "ControllerName")">
</div>
JQuery
In the below code.
- First Load the Control/Pop up.
- Get the information for your control/Pop Up
$('#dodajTemat_U').click(function () {
var MyDiv = $('#MyDiv');
var url = MyDiv.attr('Control-Url');
MyDiv.load(url, function () {
url = MyDiv.attr('Action-Url');
$.ajax({
url: url,
async: true,
type: 'POST',
beforeSend: function (xhr, opts) {
},
contentType: 'application/json; charset=utf-8',
complete: function () { },
success: function (data) {
}
});
});
});
If you pay attention, to the above code, I am fetching two Url.
- For the Pop Up/Partial View for load
- For the Model and pass the Model information to PopUp.
You should send the Model information to the control from Action Method and not from the javaScript.
Controller Action for Partial View Load
//For loading the Pop-Up or for the Partial View
[HttpGet]
public PartialViewResult YourActionName()
{
return PartialView("PartialViewName");
}
//For fetching the Model information and pass it to View.
public JsonResult ActionForGetInformation()
{
return Json(Your Model Information goes here, JsonRequestBehavior.AllowGet);
}