views:

429

answers:

3

for example you have custom route like this:

CustomerOrder/{action}/{id}/customerid={customerid}

the url became like this:

CustomerOrder/Create/customerid=1

how can you get the customerid and use it in the view?

<%= Html.MenuItem("Back to List", "Index", new { customerID = ???????? })%>

+2  A: 

The equals sign is going to confuse url parsers since it has special meaning.

If you were to change your route to:

routes.MapRoute("CustomerOrder", "CustomerOrder/{action}/{id}",
    new { controller = "Order", id = "" });

Then the following view code

<%= Html.MenuItem("Back to List", "Index", new { customerID = 5 })%>

Would create a link to:

CustomerOrder/Index/?customerid=5

which would work just fine.

Note

Given your current routing configuration, you would get the exact same results by deleting your CustomerOrder route since it is broken and you get the desired results from the default route.

Stefan Rusek
I tried to change it to <code> ?customerid = 1 </code> but this error occured..The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.Parameter name: routeUrl
Fleents
@fleents: Can you copy your route configuration in Global.asax.cs? It would probably help. And put it in your original question. Not here...
Robert Koritnik
@Fleents: you can't put querystrings in the route. Phil Haack discusses that they're not used here: http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx#58629
Dan Atkinson
A: 
Fleents
CustomerOrders isn't a correct url, as you're not specifying a ? in any case.
Dan Atkinson
Surely, at the least, you should have to do: CustomerOrder/{action}/{id}/?customerid={customerid}
Dan Atkinson
Please update your question with this, rather than add it as a new answer.
Dan Atkinson
i got it..the url must be CustomerOrder/{action}/{customerid}/{id}because customerid always have a value.now going back to my question. since the url is CustomerOrder/Index/1and 1 is the customerid (not orderid),if i have an actionlink like this in my Index View,Html.ActionLink("Create New Order", "Create", new {projectid = ?????})how can i get the value of the projectid(?????) so i can pass it to the create action?
Fleents
A: 

I'm new to MVC but I'm thinking the controller gets a customerid parameter and that could be passed to the View (via ViewData), no?

machine elf