选择模型的属性并将其添加到表单中

时间:2014-06-11 14:23:18

标签: asp.net-mvc

我正在尝试获取表单的属性,并将其与我的表单一起提交到Post方法中。我真的不需要确切的语法,但我不确定我将用它来完成这个逻辑。

1 个答案:

答案 0 :(得分:1)

模型        [DisplayName("User ID.")] public int id { get; set; } [DisplayName("Name")] public string name { get; set; } [DisplayName("Email")] public string Emailid{ get; set; }

查看

@model projectname.Models.modelclassname
@using (@html.beginform("Index","Home",formmethod.post)){
 @Html.LabelFor(model=>model.id)
 @html.textboxfor(model=>model.id)
 @Html.LabelFor(model=>model.name)
 @html.textboxfor(model=>model.name)
 @Html.LabelFor(model=>model.emailid)
 @html.textboxfor(model=>model.emailid)
<input id="submit" type="submit" value="Submit"/>
}

控制器将有post方法

    public actionresult index(FormCollection formvalueinstance)
   {
    string id = formvalueinstance["id"];
    string name= formvalueinstance["name"];
    string emailid= formvalueinstance["idemailid];
         }