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

0

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

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 :) ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.