HTML.ActionLink method

前端 未结 10 1404
刺人心
刺人心 2020-11-22 11:07

Let\'s say I have a class

public class ItemController:Controller
{
    public ActionResult Login(int id)
    {
        return View(\"Hi\", id);
    }
}


        
相关标签:
10条回答
  • 2020-11-22 11:42

    what about this

    <%=Html.ActionLink("Get Involved", 
                       "Show", 
                       "Home", 
                       new 
                           { 
                               id = "GetInvolved" 
                           }, 
                       new { 
                               @class = "menuitem", 
                               id = "menu_getinvolved" 
                           }
                       )%>
    
    0 讨论(0)
  • 2020-11-22 11:47

    With MVC5 i have done it like this and it is 100% working code....

    @Html.ActionLink(department.Name, "Index", "Employee", new { 
                                departmentId = department.DepartmentID }, null)
    

    You guys can get an idea from this...

    0 讨论(0)
  • 2020-11-22 11:48

    I wanted to add to Joseph Kingry's answer. He provided the solution but at first I couldn't get it to work either and got a result just like Adhip Gupta. And then I realized that the route has to exist in the first place and the parameters need to match the route exactly. So I had an id and then a text parameter for my route which also needed to be included too.

    Html.ActionLink(article.Title, "Login", "Item", new { id = article.ArticleID, title = article.Title }, null)
    
    0 讨论(0)
  • 2020-11-22 11:48

    Use named parameters for readability and to avoid confusions.

    @Html.ActionLink(
                linkText: "Click Here",
                actionName: "Action",
                controllerName: "Home",
                routeValues: new { Identity = 2577 },
                htmlAttributes: null)
    
    0 讨论(0)
提交回复
热议问题