In this Article, Describe how to Remove UrlParameter using MVC Routing in asp.net mvc. If you new to Routing in mvc please refer to this link for more details http://www.infinetsoft.com/Post/What-is-Routing-in-asp-net-mvc/106
Here I explain with small demonstration to achieve this. I have passed two parameter with name of value and id in my url. I want to remove last two passing parameter name value and id.
For example let you assume this is my url link
http://localhost:12345/User?value=98998?id=2
Step -I
=========
//Modify your Routeconfig.cs like this
routes.MapRoute(
"User",
"User/{value}/{id}",
new { controller = "User",action = "Index", value= UrlParameter.Optional, id =UrlParameter.Optional }
);
Step-II
========
//User Controller
public ActionResult Index(string value,int id)
{
// write Your logic here
return view();
}
Step-III
========
//Create an Index view for UserController
@Html.ActionLink("LinkName", "Index","User", new {value = "98998", id = "2"},null)
Output
http://localhost:12345/User/98998/2
Likewise we can remove multiple parameter name from the url.
Post your comments / questions
Recent Article
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article