c# - Asp.net MVC URL routing: issue changing URL when has parameters -


i need change urls in mvc project, , far has been quite simple - i've had change url string in appropriate routes.maproute() in global.asax.cs file.

one link in particular acting stubborn , won't change, , i'm sure it's because 1 parameters.

the maproute in question is:

routes.maproute(             "mortgage.getthisrate",             "mortgage-rates/mortgage-rate-details/{groupid}/{paymenttype}/{mortgagevalue}/{province}",             new { controller = "mortgage", action = "getthisrate", paymenttype = urlparameter.optional, mortgagevalue = urlparameter.optional, province = urlparameter.optional },             new { groupid = "\\d+", paymenttype = "\\d+", mortgagevalue = "\\d+", province = "\\d+" }         ); 

and button calling maproute is:

 @html.omniturebutton( url.action("getthisrate", new { groupid = info.groupid }), "<span class=\"payment\"></span><br />get details", new {@class = "orange"}, "events", "event3", "", "event3", "", "mortgage learnmore") 

when button pressed, url requests is: http://www.apps.mysite.net/mortgage/getthisrate/8/48/200000/1 - ignoring url string in maproute method, seem.

i've tried placing maproute() @ top of global.asax.cs, ensure it's not being ignored higher priority route, same problem persists.

anybody knowledgeable in mvc routing able puzzle out what's wrong here?

forgot groupid parameter, should (already tested , works fine)

routes.maproute(         "mortgage.getthisrate",         "mortgage-rates/mortgage-rate-details/{groupid}/{paymenttype}/{mortgagevalue}/{province}",         new { controller = "mortgage", action = "getthisrate", groupid = urlparameter.optional, paymenttype = urlparameter.optional, mortgagevalue = urlparameter.optional, province = urlparameter.optional },         new { groupid = "\\d+", paymenttype = "\\d+", mortgagevalue = "\\d+", province = "\\d+" } 

and build link helper must especifiy name of route want use

@html.routelink("title of link", "mortgage.getthisrate", new { groupid = "8", paymenttype = "48", mortgagevalue = "200000", province = "1" }) 

so, link looks like...

yoursite/mortgage-rates/mortgage-rate-details/8/48/200000/1 

i see you're using custom controls, can generate url of action @url.routeurl , give custom control html parameter

@url.routeurl("mortgage.getthisrate", new { groupid = "8", paymenttype = "48", mortgagevalue = "200000", province = "1" }) 

extends answer example case, need action link title "click me!", href controller "home", action "sayhello", class attribute "some_css" , html id "link_say_hello" solution

@html.actionlink("click me!", "sayhello", "home", null, new { id="link_say_hello", @class = "some_css"}) 

html output

<a class="some_css" href="/home/sayhello" id="link_say_hello">click me!</a> 

why attibute class has @??? because class reserved word compiler throw following error compiler error message: cs1513: } expected keep in mind.

that's great! in case need custom route, not default {controller}/{action} , use custom helper when need @url.routelink , give href html attribute...

new {href = @url.routeurl("mortgage.getthisrate", new { groupid = "8", paymenttype = "48", mortgagevalue = "200000", province = "1", id="link_say_hello", @class = "some_css" })} 

output

<a class="some_css" href="/mortgage-rates/mortgage-rate-details/8/48/200000/1" id="link_say_hello">click me!</a> 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -