Cannot convert lambda expression to type 'string' because it is not a delegate type MVC

StackOverflow https://stackoverflow.com/questions/23686151

  •  23-07-2023
  •  | 
  •  

Question

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 ?

Was it helpful?

Solution

You need to use TextBoxFor (not TextBox):

@Html.TextBoxFor(model => model.LiczbaMeczy)

That will take the lambda expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top