mvc @Html 方法总结
1:@Html.ActionLink("RSVP Now", "RsvpForm")
2:有一个model看看怎么样绑定model字段的
public class GuestResponse {
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public bool? WillAttend { get; set; }
}
@using (Html.BeginForm()) {
<p>Your name: @Html.TextBoxFor(x => x.Name) </p> //@Html.TextBoxFor(x => x.Name, new { @class = "form-control"})
<p>Your email: @Html.TextBoxFor(x => x.Email)</p>
<p>Your phone: @Html.TextBoxFor(x => x.Phone)</p> //<input id="Phone" name="Phone" type="text" value="" />
<p>
Will you attend?
@Html.DropDownListFor(x => x.WillAttend, new[] {
new SelectListItem() {Text = "Yes, I'll be there",
Value = bool.TrueString},new SelectListItem() {Text = "No, I can't come",Value = bool.FalseString}}, "Choose an option") //关注这个绑定
</p>
<input type="submit" value="Submit RSVP" /> //<form action="/Home/RsvpForm" method="post">...form contents go here...</form>
}
3:
<link rel="stylesheet" type="text/css" href="~/Content/Styles.css" /> 也可以 @Href("~/Content/Site.css")or @Url.Content("~/Content/Site.css")
4:@Html.ActionLink("Home","List","Product",null,new{@class="btn btn-block btn-default btn-lg"})
5: @Html.ActionLink("linktext", "List", "Product", new { category = model, page = 1 }, new { @class = "btn btn-block btn-default btn-lg" });
6:
@foreach (var link in Model) {
@Html.RouteLink(link, new {
controller = "Product",
action = "List",
category = link,
page = 1
}, new {
@class = "btn btn-block btn-default btn-lg"+ (link == ViewBag.SelectedCategory ? " btn-primary" : "")
})