String Parameter in url
Posted
by Ivan90
on Stack Overflow
See other posts from Stack Overflow
or by Ivan90
Published on 2010-05-08T10:21:21Z
Indexed on
2010/05/08
10:28 UTC
Read the original article
Hit count: 252
asp.net-mvc
Hy Guys, I have to pass in a method action a string parameter, because I want to implement a tags' search in my site with asp.net MVC but everytime in action it is passed a null value.
I post some code!
I try to create a personal route.
routes.MapRoute(
"TagsRoute",
"Tags/PostList/{tag}",
new {tag = "" }
);
My RouteLink in a viewpage for each tag is:
<% foreach (var itemtags in item.tblTagArt) {%>
<%= Html.RouteLink(itemtags.Tags.TagName,"TagsRoute",
new {tag=itemtags.Tags.TagName})%>,
<% } %>
My method action is:
public ActionResult PostList(string tag)
{
if (tag == "")
{
return RedirectToAction("Index", "Home");
}
else
{
var articoli = artdb.GetArticoliByTag(tag);
if (articoli == null)
{
return RedirectToAction("Index", "Home");
}
return View(articoli);
}
}
Problem is value tag that's always null, and so var articoli is always empty!
Probably my problem is tag I have to make a route contrainst to my tag parameter.
Anybody can help me?
N.B I am using ASP.NET MVC 1.0 and not 2.0!
© Stack Overflow or respective owner