views:

33

answers:

1

I got a question about MVC 2 and returning views for partials:

I got two views for creating and editing a user, the views both uses a partial so i can reuse the form fields. UserPartial.ascx, EditUser.aspx, CreateUser.aspx

I got some logic in the controller post method (EditCreateUser) which finds out if its a new or existing user which is beeing submitted and this works fine.

The problem is when I try to return the edited user: return View(user). MVC complains about EditCreateUser file not existing. But thats only the method name, i want to return the object to the EditUser view which I am already on.

I could use RedirectToAction but i rather not because this problem would occur also if i want to return the same object when some errors has occured.

Any ideas on how to do this or some pointers in the right direction would be awesome. Thanks

+2  A: 

Within an action method named EditCreateUser, the statement return View(user) will by default look for a view with the same name as the action. You need return View("EditUser", user)

Clicktricity
Sorry for the late answer/comment.. This worked fine, thank you Clicktricity. The only problem is that the url will be EditCreateUser instead of EditUser/xx . But i guess thats fine, if someone doesn't have any idea of how to get around this :) ?
Andreas