I am trying to build a form using Razor template engine with ASP.NET MVC 5.
I have the following encapsulated call which I pass to the main view
public class ManagePresenter
{
public ActionFormViewModel ActionForm { get; set; }
public List<SelectListItem> Users { get; set; }
}
Then I have this view
@using(Html.BeginForm("Index", "Manage", FormMethod.Post, new { @class = "form-inline", Id = "ManageEmployeeForm" }))
{
Html.AntiForgeryToken();
Html.HiddenFor(m => m.ActionForm.From);
Html.HiddenFor(m => m.ActionForm.To);
<div class="form-group">
@{
Html.LabelFor(m => m.ActionForm.UserId, new { @class = "sr-only" });
Html.DropDownListFor(x => x.ActionForm.UserId, Model.Users, new { @Class = "form-control" });
Html.ValidationMessageFor(m => m.ActionForm.UserId);
}
</div>
<div class="checkbox">
<label>
<label>
@Html.CheckBoxFor(m => m.ActionForm.ShowAlternateEntries, new { Title = "Alternate entries are entries from the telephony system that will help you compare against manual entries" })
</label>
</label>
</div>
<button type="submit" class="btn btn-primary" id="ManageEmployeeGetTime">View Records</button>
}
but every time I run my application I get the following error
CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'DropDownListFor' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>, object)' has some invalid arguments
What could be causing this error? Model.Users is a List<SelectListItem>
What am I missing here?
DropDownListForI found acceptIEnumerable<SelectListItem>. - kiziuSelectListItemin the model is from a different version of MVC? - kiziuHtml.AntiForgeryToken();needs to be@Html.AntiForgeryToken()(and ditto for the hidden inputs - user3559349System.Web.WebPages.Html.SelectListItem(or you have created your own class) instead of the requiredSystem.Web.Mvc.SelectListItem- user3559349