I'm new to MVC, so apologies for the noob question!
I have the following model (TimeEntry), used for entering timesheet details:
namespace MVCLogin.Models
{
public class TimeEntry
{
public int TimeEntryID { get; set; }
public int TaskTypeID { get; set; }
[ForeignKey("TaskTypeID")]
public virtual TaskType TaskType { get; set; }
public double MonHours { get; set; }
public double TueHours { get; set; }
public double WedHours { get; set; }
public double ThuHours { get; set; }
public double FriHours { get; set; }
}
}
Task type is based on the following model:
namespace MVCLogin.Models
{
public class TaskType
{
public int TaskTypeID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
I use the following partial view which is used for entering the timesheet details:
<div class="col-md-1">
@Html.EditorFor(model => model.TaskType)
@Html.ValidationMessageFor(model => model.TaskType)
</div>
<div class="col-sm-1">
@Html.TextBoxFor(model => model.MonHours , new { style = "width:100%", @class = "hours mon" })
@Html.ValidationMessageFor(model => model.MonHours)
</div>
<div class="col-sm-1">
@Html.TextBoxFor(model => model.TueHours, new { style = "width:100%", @class = "hours tue" })
@Html.ValidationMessageFor(model => model.TueHours)
</div>
<div class="col-sm-1">
@Html.TextBoxFor(model => model.WedHours, new { style = "width:100%", @class = "hours wed" })
@Html.ValidationMessageFor(model => model.WedHours)
</div>
<div class="col-sm-1">
@Html.TextBoxFor(model => model.ThuHours, new { style = "width:100%", @class = "hours thu" })
@Html.ValidationMessageFor(model => model.ThuHours)
</div>
<div class="col-sm-1">
@Html.TextBoxFor(model => model.FriHours, new { style = "width:100%", @class = "hours fri" })
@Html.ValidationMessageFor(model => model.FriHours)
</div>
I want the task type field to be a drop down, but I can't figure out how to wire it up. The classes and data are right, as if I scaffold a controller (using Visual Studio's Add Controller tool) for the TimeEntry class it works fine:
<div class="form-group">
@Html.LabelFor(model => model.TaskTypeID, "TaskTypeID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("TaskTypeID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.TaskTypeID, "", new { @class = "text-danger" })
</div>
</div>
How can I get the dropdownlist to work in the partial view?
