String Parameter in url
- by Ivan90
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!