0

I have this code that creates an url

<a href="ContactInformation/CreateContactInformation/[email protected]" class="ContactInformationEdit">Add New</a>

(I couldnt find out how to make an actionlink that used an action, controller, object and where I could put a classname on for use in javascript)

That gives a link like this http://localhost:51730/ContactInformation/CreateContactInformation/dossierId=1

I then have a controller action

[HttpGet]
    public ActionResult CreateContactInformation(int? dossierId)
    {
        return PartialView("ContactInformationCreate", new ContactInformationViewModel(dossierId.Value));
    }

But if I put a breakpoint in that code then the variable is just "null" doing a request param gives same result

3 Answers 3

3
<a href="ContactInformation/CreateContactInformation/[email protected]" class="ContactInformationEdit">Add New</a>

i.e. You missed the ? before your query string

Sign up to request clarification or add additional context in comments.

1 Comment

Ha. Easy mistake. We all make them.
2
ContactInformation/CreateContactInformation/[email protected] 

Should be

ContactInformation/[email protected]

Url.Action helper is used to generate only link. And you could use that link in whatever you like, anchor or anything else. But there also is builtin ActionLink overload to generate exactly what you want.

@Html.ActionLink("Add New", "CreateContactInformation", "ContactInformation", new {dossierId = @Model.DossierId}, new {@class="ContactInformationEdit"})

Code above will regard your route configuration too

Comments

0

Have you got the routing right?

routes.MapRoute( _
"ContactInformation" _
"ContactInformation/CreateContactInformation/{parameters}" _
new With { .controller = "ContactInformation", .action = "CreateContactInformation"})

And then

<a href="ContactInformation/[email protected]" class="ContactInformationEdit">Add New</a>

1 Comment

And also, sorry for the VB.NET syntax on routing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.