What I want to do is to populate SelectList with categories from a categories repository.
A little mockup http://mockupbuilder.com/App/15379.
What I have now is a controller:
[HandleError]
public class ProductController : Controller {
private IRepository<Product> exhibitions;
private IRepository<Category> categories;
private readonly Int32 PageSize = 18;
// ctor ...
[HttpPost]
public ActionResult Create(Product product, Guid categoryId) {
// validation ...
// properties setting ...
product.Category = categories.Get(categoryId);
return View(product);
}
Category class is like this:
public class Category : AbstractEntity<Category> {
public String Title { get; set; }
public String Description { get; set; }
}
How do I populate a SelectList? How do I make this using JSON?
Thanks!
You can put the List in viewbag and render it using aspx code. Something like below:
And in your view page, something like this:
If you want to populate the categories via json.
You have to write a new action in your category controller like:
And in your page’s js logic use ajax to call it and handle the result.