Reputation: 73
I'm having trouble with my contact form. It says: Compiler Error Message: CS1963: An expression tree may not contain a dynamic operation. I tried to use the @using ... statement without luck. I also used the @models with both capital and lower case "m" and no luck. Please explain with great detail the solution(s). I'm using Visual Studio 2012, if it helps.
Here is the code; 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> }
model:
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;
}
}
}
Upvotes: 2
Views: 14861
Reputation:
At the top of the view, it should be
@model img_site.Models.customer
not
@Model img_site.Models.customer;
then in your expressions, it should be
@Html.EditorFor(m => m.Fname, ...
not
@Html.EditorFor(m => Model.Fname, ...
Upvotes: 6