Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

asp.net razor: url param is not handed over

in my asp.net razor page i have a dynamically rendered button:

 <a href="@Url.Action("AddSubSub", "GlobalTagging", new { idOfSubsub = 3});">Add Subsub</a>

which fires this function:

public ActionResult AddSubSub(int? idOfSubsub)
{
    return RedirectToAction("Index", new { searchword = "" });
}

however, idOdSubsub is always returned as null, never as "3". Which i gave it in the <a>.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why isnt the param handed over?

>Solution :

I just tested this and the problem is the semicolon at the end of your href, with the semicolon it produced an href of: /GlobalTagging/AddSubSub?idOfSubsub=3; (Doesn’t work):

<a href="@Url.Action("AddSubSub", "GlobalTagging", new { idOfSubsub = 3});">Add Subsub</a>

If you remove the semicolon, it works and produces an href of: /GlobalTagging/AddSubSub?idOfSubsub=3 (Works):

<a href="@Url.Action("AddSubSub", "GlobalTagging", new { idOfSubsub = 3})">Add Subsub</a>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading