I have a form that wanna to select category and tag from drop down list and bind it to a post , this is my ViewModel:
public class PostViewModel
{
public IList<Category> Category { get; set; }
public IList<Tag> Tag { get; set; }
}
and this is my get action :
public ActionResult Add()
{
ViewBag.CategoryList = new SelectList(_categoryRepository.GetAllCategory());
ViewBag.TagList = new SelectList(_tagRepository.GetAllTag());
return View();
}
now how can I get the Id dropdownlst to send it to the Post action?? :
<div>
@Html.LabelFor(post => post.Category)
@Html.DropDownListFor ????
@Html.ValidationMessageFor(post => post.Category)
</div>
I tried this one it it didn't work
<div>
@Html.LabelFor(post => post.Category)
@Html.DropDownListFor(post => post.Category, ViewBag.CategoryList as SelectList, "--- Select Category ---")
@Html.ValidationMessageFor(post => post.Category)
</div>
please give me a solution about this ,thanks