码迷,mamicode.com
首页 > Web开发 > 详细

MVC之htmlhelper

时间:2015-08-31 23:12:17      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

View

@model 知识点.Models.Pig

@{
Layout = null;
}
@using 知识点


<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Edit</title>
</head>
<body>

<div>
@* <form action="/C01HtmlHelperDemo/Edit" method="post">
<input type="submit" value="提交"/>
</form>*@

生成表单的方式

@using (Html.BeginForm("Edit", "C01HtmlHelperDemo", FormMethod.Post))
{
@Html.TextBoxFor(c => c.Name)<br />
@Html.PasswordFor(c => c.Pwd) <br />
@Html.CheckBoxFor(c => c.Gender)<br />
@Html.RadioButtonFor(c => c.Color, "1")
@Html.RadioButtonFor(c => c.Color, "2")

<br />
@Html.DropDownListFor(c => c.Color, new List<SelectListItem> {
new SelectListItem{ Text="黑色", Value="1"},
new SelectListItem{ Text="白色", Value="2"},
})
<br />

@Html.ActionLink("跳转1","Edit","C01HtmlHelperDemo")

@Html.Submit("提交")
}
</div>
</body>
</html>

 

Contorller

public class C01HtmlHelperDemoController : Controller
{
//
// GET: /C01HtmlHelperDemo/

public ActionResult Edit()
{
Pig pig = new Pig { Name = "家猪", Age = 1, Color = 2, Gender = false, Pwd = "123" };

return View(pig);
}

}

 

 

Model

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

public class Pig
{
[Required(ErrorMessage = "非空")]
public string Name { get; set; }
public int Age { get; set; }
public string Pwd { get; set; }
public bool Gender { get; set; }
public int Color { get; set; }
}

MVC之htmlhelper

标签:

原文地址:http://www.cnblogs.com/anling-yao/p/4774345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!