in

Chennai .Net User Group

A platform that enables you to Learn, Share & Grow (India's first .Net user group)

Shiju Varghese's Blog

QueryString values along with id parameter in ASP.NET MVC

 A number of folks have asked me how to pass query string values along with a route parameter id. They are looking onto send a url like  http://MySite/Home/Edit/5?name=shiju.

The below is the routing configuration

 

routes.MapRoute(

    "Default",                                            

    "{controller}/{action}/{id}",                        

    new { controller = "Home", action = "Index", id = UrlParameter.Optional }

);

 

 

We need to pass route information for id parameter and also attach query string values. The below is our action method

 

public ActionResult Edit(int id,string name)

{

    //To Do

    return View();

}

 The below action method would set values for id parameter and query string parameter name.

<%=Html.ActionLink("Edit","Edit",new { id=5,name="shiju"}) %>

The ActionLink helper would generate the following markup

<a href="/Home/Edit/5?name=shiju">Edit</a> 

 

Our Action method would automatically taken the value 5 for id and value "shiju" for name. This is really nice feature and convention of ASP.NET MVC

Read the complete post at http://feedproxy.google.com/~r/ShijuVBlog/~3/QYeR7c58cL8/querystring-values-along-with-id-parameter-in-asp-net-mvc.aspx

Only published comments... Feb 26 2010, 07:44 AM by Shiju Varghese's Blog
Filed under: ,
Copyright © 2002-2008 Chennai .Net User Group. All Rights Reserved. Microsoft and Microsoft logo's are trademarks of Microsoft Corporation