[收集]MVC3 HTML辅助方法集录

时间:2022-09-28 03:07:10

1.跳转链接

@Html.ActionLink("linkText","actionName",routeValues,htmlAttributes)
e.g<%:Html.ActionLink("删除", "DeleteUser", new { id = Model.UserId },new{ onclick = "return confirm('确认删除?')"})%>

2.链接和传值

<a href="@Url.Action("方法","类名", new {参数名 = 参数值 })
e.g. <a href="<%=Url.Action("CompanyInfo", "Company", new { stockId = "11111" })%>" >

3.表格提交值

@Html.Textbox("username") 输入值
@Html.Hidden("ProductId",line.Product.ProductID) 隐藏输入值