Wednesday, 18 September 2013

How to use href attribute in mvc4

How to use href attribute in mvc4

I am having a < href > attributes in my .cshtml page at mvc4 @cp.Name in
my mvc 4 .... what i need is if a person clicks the above link . i have to
redirect him to any of the ActionName in Controller (for eg: Index in
HomeController )...... how to do it. In my above sample i have redirected
to google.com...... but i need to redirect to any of actionname in
controller...... My code:
<nav> @{ List<MenuRazor.Models.MenuItem> menulist = ViewBag.Menu; }
<ul id="menu">
@foreach (var mp in menulist.Where(p => p.ParentMenu_Id == 0)) {
<li> <a href="#">@mp.Name</a>
@if (menulist.Count(p => p.ParentMenu_Id == mp.Id) > 0)
{ @:<ul> }
@RenderMenuItem(menulist, mp)
@if (menulist.Count(p => p.ParentMenu_Id == mp.Id) > 0){@:</ul> }
</li> }
</ul>
@helper RenderMenuItem(List<MenuRazor.Models.MenuItem> menuList,
MenuRazor.Models.MenuItem mi)
{
foreach (var cp in menuList.Where(p => p.ParentMenu_Id == mi.Id)) {
@:<li> <a href="http://codeproject.com">@cp.Name</a>
if (menuList.Count(p => p.ParentMenu_Id == cp.Id) > 0) {
@:<ul>
}
@RenderMenuItem(menuList, cp)
if (menuList.Count(p => p.ParentMenu_Id == cp.Id) > 0) {
@:</ul>
} else {
@:</li>
}
} } </nav>

No comments:

Post a Comment