Reputation: 435
ContestM ->Model's property
public SelectList EmployeeList { get; set; }
public int EmployeeId { get; set; }
Controller action
On button click from main view,this action is being hit and at the end after processing data for dropdown from db ,i assigning value to dropdown object and trying to display the value in partial view
public ActionResult AssignContest()
{
try
{
int id = 3;
var res = ContestVM.getTLEmployees(id).ToList();
var eList = new ContestM();
eList.EmployeeList = new SelectList(res, "EmployeeId", "FirstName");
return PartialView("Assign", new ContestM() { EmployeeList = eList.EmployeeList });
}
catch (Exception ex)
{
ViewData["error"] = ex.Message.ToString();
return View("~/Views/Shared/LogoutOrInvalid.cshtml");
}
}
my Razor view (assign.cshtml)
@model Performance.Launcher.Models.ContestM
@using (Html.BeginForm("AssignContest", "Contest", FormMethod.Post, new { id = "frmContestAssignContest" })))
{
//var emplistdata= ViewData["employeesList"];
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Contest</h4>
<hr />
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ContestId)
<div class="form-group">
@Html.LabelFor(model => model.EmployeeId, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.EmployeeId, Model.EmployeeDet, "Choose...", new { htmlAttributes = new { @class = "form-control col-md-2" } })
//@Html.DropDownList("dropdown1", ViewData["employeesList"])
//@Html.ValidationMessageFor(model => model.EmployeeId)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
Not able to find where i am going wrong .Any help is greatly appreciated.
Upvotes: 2
Views: 1044
Reputation: 35260
It looks like you have an extra )
on the end of this line:
@using (Html.BeginForm("AssignContest", "Contest", FormMethod.Post, new { id = "frmContestAssignContest" })))
By the way, if you want to know how I figured it out so fast, I just used my browser's "find" and searched for ")" until I found one that didn't have a matching "(" before it, and it was right before a {
, so I knew that was the one. You should take error messages for what they mean; a lot of the time they're pretty clear and helpful.
Upvotes: 5