Asp.Net Mvc - RenderAction - Create in a list view?

AcceptVerbs(HttpVerbs. Post) public ActionResult Create(Product product) { ... return View("List"); } or AcceptVerbs(HttpVerbs. Post) public ActionResult Create(Product product) { ... return RedirectToAction("List", "Product"); }.

The second option work but my Create form isn't validate. I mean I didn't see the error validation message. – Melursus Jan 22 '10 at 0:13.

Your controller should work like this: public class ProductController : Controller { IList products; public ProductController( ) { products = new List(); products. Add(new Product() { Id = 1, Name = "A", Price = 22.3 }); products. Add(new Product() { Id = 2, Name = "B", Price = 11.4 }); products.

Add(new Product() { Id = 3, Name = "C", Price = 26.5 }); products. Add(new Product() { Id = 4, Name = "D", Price = 45.0 }); products. Add(new Product() { Id = 5, Name = "E", Price = 87.79 }); } public ActionResult List( ) { return View(products); } public ActionResult Create() { return View(); } AcceptVerbs(HttpVerbs.

Post) public ActionResult Create(Product product) { products. Add(product); return View("List", products); } } Additionally, you need to call RenderPartial instead of RenderAction, because otherwise your POST method will be invoked (due to you did a post-command by submitting the form): This should work, you only need to persist your products list, as it will reset with every postback. I hope this helped you :).

Does your product object declare it's properties like this; public string Name {get;set;} You must have getters and setters on your objects. EDIT Wait, are you wanting fields from your list View to be available in the post to your create action? If yes then you need to place the BeginForm at the View level and not the PartialView level.

Only fields contained within the begin form will be posted to your controller. EDIT 2 Ah, I think I see it now.In your controller I think you should do a product. IsValid to check first.

But in your html you should also do this; You need to fill in the value for the text box. Hope this is what you were after.

Yes, I declare them like that – Melursus Jan 21 '10 at 23:32 I put more code. May be not you will better understand my problematic. What I want it's a listing and a create widget (that's why I use RenderAction) in the same page.

The first time I load the page, that's work correctly. The problem come when I try to add a new product. The post action work correctlt but the returned view is the create.

Ascx view without the listing and without the style. – Melursus Jan 21 '10 at 23:58.

I use Asp.Net Mvc 1 with Asp.Net Futures (which have the Html.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions