I have a function CreatePerson(int id)
, I want to pass id
from @Url.Action
.
Below is the reference code:
public ActionResult CreatePerson(int id) //controller window.location.href = "@Url.Action("CreatePerson", "Person") + id";
the above code fails to pass id
value to CreatePerson
function.
You can concat the client-side variables with the server-side url generated by this method, which is a string on the output. Try something like this: var firstname = "abc"; var username = "abcd"; location. href = '@Url.
Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".
You can pass them via a URL, a query string, a request header, a request body, or even a form.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With