1

I have a DashBoardController.cs here i have this code

public class DashBoardController : Controller { // // GET: /DashBoard/ [Authorize] public ActionResult Index() { return View(); } // // GET: /New Project/ [Authorize] public ActionResult NewProject() { return View(); } // // GET: /File Upload/ public ActionResult UploadFile() { return View(); } [HttpPost] public ActionResult UploadFile(HttpPostedFileBase file) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder var path = Path.Combine(Server.MapPath("~/Uploads"), fileName); file.SaveAs(path); } // redirect back to the index action to show the form once again return RedirectToAction("Index", "Home"); } } 

I have another masterlayout file here i have this code

<div id="LeftColumn" class="ui_style_floatLeft"> <div id="menuWrapper"> <ul class="menu"> <li class="menuDashBoard">@Html.ActionLink("Dashboard","Index")</li> <li class="menuProject"><a href="#">Project</a> <ul> <li>@Html.ActionLink("New Project","NewProject")</li> <li><a href="#">Projects</a></li> </ul> </li> <li class="menuAccount"><a href="#">Account</a> <ul> <li>@Html.ActionLink("Change Password", "ChangePassword", "Account")</li> </ul> </li> </ul> </div> </div> 

But If i goto Change Password action link then other link (New Project, Dashboard) not working. i try @Url.Action into a herf attr but not working :(

what should i do now ?

4 Answers 4

1
  • LinkText: "Dashboard"
  • ActionName: "index"
  • ControllerName: "dashboard"

    @Html.ActionLink("Dashboard", "index", "dashboard")

If you are using areas to group controllers into different areas you would need.

@Html.ActionLink("Dashboard", "index", "dashboard", new { area = "YourAreaName"}) 
Sign up to request clarification or add additional context in comments.

1 Comment

I am new in MVC3. What Area actually did ? Can you give me a link where i can know about Area ?
1

You need to include the controller name in your action link:

@Html.ActionLink("Dashboard","Index","DashBoard") 

If you leave out the controllerName, then the links will be constructed with the current controller. Since you navigated to the AccountController, the link that was supposed to point to the DashboardController broke.

In shared areas (like navigation), you'll usually want to include the controller reference.

1 Comment

Yes man but it only work for this @Html.ActionLink("New Project","NewProject","Project") but @Html.ActionLink("Dashboard","Index","DashBoard") not working :(
0

Use this overload

@Html.ActionLink("New Project","NewProject","DashBoard") 

this is the format

public static MvcHtmlString ActionLink( this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName ) 

2 Comments

Thank you my friend, but it work for only NewProject link but not for DashBoard Index :(
Did you use the same overload for the link for Index action ?
0

Take a look closely, I think you did not put the controller for the "NewProject" and "Index" methods

try replacing

@Html.ActionLink("New Project","NewProject") 

for

@Html.ActionLink("New Project","NewProject", "DashBoard") 

and

@Html.ActionLink("Dashboard","Index") 

for

@Html.ActionLink("Dashboard","Index", "DashBoard") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.