2011-12-28 84 views
3

我有以下MVC @ Html.ActionLink與名稱

@Html.ActionLink("Edit", "EditProg", new { id = item.ID }) 

我想知道怎麼也供應上面有名字,因爲我需要它的陷阱提交前這個名字。有沒有像name = "EditLink"

回答

5

你的意思是像添加一個name屬性到錨點(即使這個屬性在錨點上無效)?

@Html.ActionLink(
    "Edit",      // linkText 
    "EditProg",     // actionName 
    new { id = item.ID },   // routeValues 
    new { name = "EditLink" }  // htmlAttributes 
) 

或將其作爲查詢字符串參數發送給控制器?

@Html.ActionLink(
    "Edit",     // linkName 
    "EditProg",    // actionName 
    new {     // routeValues 
     id = item.ID, 
     name = "some name" 
    } 
) 
0

你可以用Url.Action代替嗎?

<a href="@Url.Action("EditProg")" id="@item.ID" name="editlink" >

+0

爲什麼使用這樣的事情時,已經是一個ActionLink的過載,允許實現呢? –