Phone asp.net 控制器中的编号
Phone number in asp.net controller
我正在制作一个请求系统,该系统将用于查找与客户相关的数据,但我遇到了一个小问题,您究竟如何编写 phone 号码的代码ASP.NET 的控制者?这是我目前在控制器中的内容:
public ActionResult Person()
{
Person hooman = new Person()
{
FirstName = "Parker",
LastName = "Smith",
Age = 30,
DateOfBirth = new DateTime(1988, 01, 01),
Email = "psmith@gmail.com",
//Telephone = 0851943376,
Smoker = "No",
SeriousIllness = "No",
};
return View(hooman);
}
为了以防万一,下面是 Person 控制器的一些非常基本的视图:
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Date Of Birth</th>
<th>Email</th>
<th>Telephone</th>
<th>Smoker</th>
<th>Serious Illness</th>
</tr>
<tr>
<td> @Html.DisplayFor(model => model.FirstName)</td>
<td> @Html.DisplayFor(model => model.LastName) </td>
<td> @Html.DisplayFor(model => model.Age) </td>
<td> @Html.DisplayFor(model => model.DateOfBirth) </td>
<td> @Html.DisplayFor(model => model.Email)</td>
@*<td> @Html.DisplayFor(model => model.Telephone)</td>*@
<td> @Html.DisplayFor(model => model.Smoker)</td>
<td> @Html.DisplayFor(model => model.SeriousIllness)</td>
</tr>
我一辈子都想不出如何让它发挥作用。其他都还好,就是Telephone部分搞不懂。任何帮助都将不胜感激!
看起来问题是您试图将电话号码视为 int 而不是字符串。
public ActionResult Person()
{
Person hooman = new Person()
{
FirstName = "Parker",
LastName = "Smith",
Age = 30,
DateOfBirth = new DateTime(1988, 01, 01),
Email = "psmith@gmail.com",
Telephone = "0851943376",
Smoker = "No",
SeriousIllness = "No",
};
return View(hooman);
}
应该就是你所需要的,把它当作一个字符串。
我正在制作一个请求系统,该系统将用于查找与客户相关的数据,但我遇到了一个小问题,您究竟如何编写 phone 号码的代码ASP.NET 的控制者?这是我目前在控制器中的内容:
public ActionResult Person()
{
Person hooman = new Person()
{
FirstName = "Parker",
LastName = "Smith",
Age = 30,
DateOfBirth = new DateTime(1988, 01, 01),
Email = "psmith@gmail.com",
//Telephone = 0851943376,
Smoker = "No",
SeriousIllness = "No",
};
return View(hooman);
}
为了以防万一,下面是 Person 控制器的一些非常基本的视图:
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Date Of Birth</th>
<th>Email</th>
<th>Telephone</th>
<th>Smoker</th>
<th>Serious Illness</th>
</tr>
<tr>
<td> @Html.DisplayFor(model => model.FirstName)</td>
<td> @Html.DisplayFor(model => model.LastName) </td>
<td> @Html.DisplayFor(model => model.Age) </td>
<td> @Html.DisplayFor(model => model.DateOfBirth) </td>
<td> @Html.DisplayFor(model => model.Email)</td>
@*<td> @Html.DisplayFor(model => model.Telephone)</td>*@
<td> @Html.DisplayFor(model => model.Smoker)</td>
<td> @Html.DisplayFor(model => model.SeriousIllness)</td>
</tr>
我一辈子都想不出如何让它发挥作用。其他都还好,就是Telephone部分搞不懂。任何帮助都将不胜感激!
看起来问题是您试图将电话号码视为 int 而不是字符串。
public ActionResult Person()
{
Person hooman = new Person()
{
FirstName = "Parker",
LastName = "Smith",
Age = 30,
DateOfBirth = new DateTime(1988, 01, 01),
Email = "psmith@gmail.com",
Telephone = "0851943376",
Smoker = "No",
SeriousIllness = "No",
};
return View(hooman);
}
应该就是你所需要的,把它当作一个字符串。