I have a function CreatePerson(int id)
, I want to pass id
from @Url.Action
.
Below is the reference code:
pub
public ActionResult CreatePerson (string id)
window.location.href = '@Url.Action("CreatePerson", "Person" , new {id = "ID"})'.replace("ID",id);
public ActionResult CreatePerson (int id)
window.location.href = '@Url.Action("CreatePerson", "Person" , new {id = "ID"})'.replace("ID", parseInt(id));
you can pass it this way :
Url.Action("CreatePerson", "Person", new RouteValueDictionary(new { id = id }));
OR can also pass this way
Url.Action("CreatePerson", "Person", new { id = id });
If you are using Url.Action
inside JavaScript then you can
var personId="someId";
$.ajax({
type: 'POST',
url: '@Url.Action("CreatePerson", "Person")',
dataType: 'html',
data: ({
//insert your parameters to pass to controller
id: personId
}),
success: function() {
alert("Successfully posted!");
}
});
Try this
public ActionResult CreatePerson(string Enc)
window.location = '@Url.Action("CreatePerson", "Person", new { Enc = "id", actionType = "Disable" })'.replace("id", id).replace("&", "&");
you will get the id inside the Enc string.