我的联系表格有问题。它说:编译器错误消息:CS1963:表达式树可能不包含动态操作。我没有运气就尝试使用@using ...语句。我还使用@models同时使用大写和小写" m"没有运气请详细解释解决方案。我使用的是Visual Studio 2012,如果有帮助的话。
这是代码; HTML:
@Model img_site.Models.customer;
@{
ViewBag.Title = "Contact";
<link href="~/Content/css/cnt-us_css.css" rel="stylesheet" type="text/css" />
ViewBag.update = "May14, 2014"; } ... @using (Html.BeginForm("Submit", "HomeCotroller", FormMethod.Post , new { @name = "cnt_us-frm" })) {
@Html.ValidationSummary(true)
<fieldset>
<legend></legend>
<table>
<tr>
<td>
<label for="Fname"> First name <span class="important"> * </span> </label>
</td>
<td>
@Html.EditorFor(m => Model.Fname, new { @tabindex="0"})
@Html.ValidationMessageFor(m => Model.Fname)
</td>
</tr>
<tr>
<td>
<label for="Lname"> Last name </label>
</td>
<td>
@Html.EditorFor(m => Model.Lname, new { @tabindex="1"})
@Html.ValidationMessageFor(m => Model.Lname)
</td>
</tr>
<tr>
<td>
<label for="te;_area"> Telephone <span class="important"> * </span> </label>
</td>
<td>(@Html.TextBoxFor(m => Model.tel_area, new {@size="1", @maxlength="3", @tabindex="2"}))
@Html.ValidationMessageFor(m => Model.tel_area)
@Html.TextBoxFor(m => Model.fir_thr_tel, new {@size="1", @maxlength="3", @tabindex="3"}) -
@Html.ValidationMessageFor(m => Model.fir_thr_tel)
@Html.TextBoxFor(m => Model.lst_fur_tel, new {@size="2", @maxlength="4", @tabindex="4"})
@Html.ValidationMessageFor(m => Model.lst_fur_tel)
</td>
</tr>
<tr>
<td>
<label for="Email"> Email <span class="important"> * </span> </label>
</td>
<td>
@Html.TextBoxFor(m => Model.Email , new { @tabindex="5"})
@Html.ValidationMessageFor(m => Model.Email)
</td>
</tr>
<tr>]
<td>
<label for="Reasn"> Reason <span class="important"> * </span> </label>
</td>
<td>
@Html.TextAreaFor(m => Model.Reasn, new { @tabindex="6"})
@Html.ValidationMessageFor(m => Model.Reasn)
</td>
</tr>
<tr id="buttons">
<td>
<input type="reset" id="resbnt" value="Reset" tabindex="7" />
</td>
<td>
<input type="submit" id="subnt" value="Submit" tabindex="8" />
</td>
</tr>
</table>
</fieldset> }
模型:
namespace img_site.Models
{
public class customer
{
...
[Required(ErrorMessage = "first name is required!")]
public string Fname { get; set; }
public string Lname { get; set; }
[Required(ErrorMessage = "area code is required!")]
[StringLength(3)]
[RegularExpression(@"^[0-9]{3,}$", ErrorMessage = "Minimum 3 numbers required & contain only numbers")]
public string tel_area { get; set; }
[Required(ErrorMessage = "first three numbers are required!")]
[StringLength(3)]
[RegularExpression(@"^[0-9]{3,}$", ErrorMessage = "Minimum 3 numbers required & contain only numbers")]
public string fir_thr_tel { get; set; }
[Required(ErrorMessage = "last four numbers are required!")]
[StringLength(4)]
[RegularExpression(@"^[0-9]{4,}$", ErrorMessage = "Minimum 4 numbers required & contain only numbers")]
public string lst_fur_tel { get; set; }
[Required(ErrorMessage = "E-mail is required!")]
[RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "E-mail is not valid")]
public string Email { get; set; }
[Required(ErrorMessage = "A reason is required!")]
public string Reasn { get; set; }
public string Tele { get; set; }
public void Tele_comp()
{
Tele = "(" + tel_area + ")" + fir_thr_tel + "-" + lst_fur_tel;
}
}
}
答案 0 :(得分:5)
在视图的顶部,它应该是
@model img_site.Models.customer
不
@Model img_site.Models.customer;
然后在你的表达式中,它应该是
@Html.EditorFor(m => m.Fname, ...
不是
@Html.EditorFor(m => Model.Fname, ...