【发布时间】:2014-07-02 19:10:56
【问题描述】:
我创建了一个模型,我正在尝试构建类似当我单击提交按钮时值应该传递给控制器的东西,看起来像
[HttpPost]
// i am getting checked property but not phoneno to controller
public ActionResult Confirm(Entity s)
{
return view();
}
我的观点
@model MvcApplication3.Models.Entity
@using ( Html.BeginForm("Confirm", "Home", FormMethod.Post))
{
@Html.CheckBoxFor(m=>m.checkedprop,
new
{
@class = "myCheckBox",
phoneno= "1234" //tried different ways none looks working for me
})
<input type="submit" id="ConfirmButton" />
}
型号
public class Entity
{
public bool checkedprop { get; set; }
public int phoneno { get; set; }
}
【问题讨论】:
-
phoneno没有呈现 HTML 控件。 -
是的,它是真的。!但我不能创建一个单独的 html 控件来这样做。对此有任何建议。欢呼
-
隐藏字段怎么样?
-
不,伙计,我不应该使用任何我必须使用的
@Html.CheckBoxFor。 -
顺便说一下,电话号码应该是字符串,而不是整数。如果数字以 0 开头怎么办?你会与他们相加或相除吗?如果您想查找某个区号中的所有电话号码(即以某些字符开头)等,该怎么办?
标签: asp.net-mvc razor