You need to use TextBoxFor
(not TextBox
):
@Html.TextBoxFor(model => model.LiczbaMeczy)
That will take the lambda expression.
Frage
I know there is a lot of topics like this one, but I cant find the answer.
In code:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>TabelaModel</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">
@Html.LabelFor(model => model.Druzyna)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Druzyna)
@Html.ValidationMessageFor(model => model.Druzyna);
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LiczbaMeczy)
</div>
<div class="editor-field">
@Html.TextBox(model => model.LiczbaMeczy)
@Html.ValidationMessageFor(model => model.LiczbaMeczy)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LiczbaGoliStrzelonych)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LiczbaGoliStrzelonych)
@Html.ValidationMessageFor(model => model.LiczbaGoliStrzelonych)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
Compiler is throwing an exception in line:
@Html.TextBox(model => model.LiczbaMeczy)
I have put a System.Linq, System.Data.Entity in model, in view, in controller, but still nothing. It's working when i replace @Html.TextBox into @Html.EditorFor, but i really would like to avoid this. My model class:
namespace GridViewTest.Models
{
public class TabelaModel
{
public int ID { get; set; }
public string Druzyna { get; set; }
[Required (ErrorMessage="*")]
public string LiczbaMeczy { get; set; }
[Required(ErrorMessage = "*")]
public int LiczbaGoliStrzelonych { get; set; }
}
}
Could You help me ?
Lösung
You need to use TextBoxFor
(not TextBox
):
@Html.TextBoxFor(model => model.LiczbaMeczy)
That will take the lambda expression.