I have something like this
[HttpPost]
public ActionResult CreatePost(Post post)
{
var categoryList = Request["CategoryList"].Split(',');
//I want to set my Category Name in here
foreach (var category in categoryList)
{
post.Categories.Add(new Category { Name = category });
}
post.CreatedDate = DateTime.Now;
post.CreatedBy = _userService.GetCurrentUser().Id;
_postService.CreatePost(post);
return View();
}
I want to set public virtual ICollection<Category> Categories { get; set; }
this is in my Post Model. It has two properties Id
and Name
. I want to set my property in my CreatePost
method like above. How should I do that?