1

I have the following in my controller where I am passing in 2 parameters:

    url = Url.Action("ViewReq ", "ProgramT ", new   System.Web.Routing.RouteValueDictionary(new { id = spid pgid = pid }), "http", Request.Url.Host);

When I view this, it shows up as:

    http://localhost/Masa/ProgramT/ViewReq/20036?pgid=00001

I like it to show up as:

http://localhost/Masa/ProgramT/ViewReq?id=20036&pgid=00001

How do I modify the UrlAction to show this way?

2 Answers 2

3

You could modify your default route registration in Global.asax so that the {id} token is not part of your urls. Remove it or something.

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

2 Comments

@Darvin Dimitrov - How can I modify the Url.Action in the sample I have above so that it shows it as localhost/Masa/ProgramT/ViewReq?id=20036&pgid=00001 as this will give me the absolute path. Thank you
@NatePet, you can't modify Url.Action. It's a method that's part of the ASP.NET MVC framework. As I said in my answer, modify your routes, as that's what the Url.Action method uses to generate those urls.
2

I believe the Darin is correct.

To get the URL that you desire, just keep your URL generation code the same

Url.Action("ViewReq ", "ProgramT ", new   System.Web.Routing.RouteValueDictionary(new { id = spid, pgid = pid }), "http", Request.Url.Host);

Then in the Global.asax file you add the following route below the default route.

 routes.MapRoute(
       "YourNewRoute", // Route name
       "ProgramT/ViewReq/{id}/{pgid}", // URL with parameters
       new { controller = "ProgramT", action = "ViewReq",  id = UrlParameter.Optional, pgid = UrlParameter.Optional  } // Parameter defaults
   );

You should then see the URL as (assuming that id is 20036 and pgid is 00001)

http://localhost/Masa/ProgramT/ViewReq/20036?pgid=00001

Comments

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.