【发布时间】:2011-06-01 05:38:17
【问题描述】:
我有一个表单,希望用户在其中输入电话号码。但是,表单看起来像这样:
[FormField-1] - [FormField-2] - [FormField-3]
这里有三个文本框,方便用户以 xxx-xxx-xxxx 格式输入。但是,我的模型类是:
class Person
{
[Required(ErrorMessage="Phone Mandatory!")]
public string phone {get; set;}
}
我的看法是这样的:
@model MvcApplication1.Models.Person
@using ( Html.BeginForm("Create", "Home"))
{
@Html.TextBoxFor( model => model.phone )
@Html.ValidationMessageFor( model => model.phone )<br />
<input type="submit" value="submit" />
}
如何解决这个问题,这样我就不必拥有三个不同的类属性来匹配代表电话号码的 3 个不同的表单字段?
谢谢!
【问题讨论】:
标签: c# asp.net-mvc razor