开发者

mvc how can i return back to an action that calls RedirectToAction(..)?

开发者 https://www.devze.com 2023-01-08 01:09 出处:网络
I have an action Create() on my BooksController, where I create a new Book class.Part ofthis create process is to add one or more Authors, where Author is a class.

I have an action Create() on my BooksController, where I create a new Book class. Part of this create process is to add one or more Authors, where Author is a class.

开发者_运维百科

Here's the way I envision this working:

When user clicks "Create a new book" they are returned the Create view.

User can click "Add Author" button at any time. "Add Author" posts and saves all data in session, then RedirectToAction("Search", "Author", new { returnController="Books" returnAction="AddAuthor" } (pseudo)

That will return an AuthorId to the AddAuthor Action, which gets the new Book class out of session, updates with author, and redirects back to Create()

My question - is this the best way to handle a 'return to' with MVC? What if I wanted to have the Author Search include an 'add new author' option? I'd want to return to one URL, that returned the ID to a second URL. seems really confusing, could use some help. thanks.


I suggest that u make your AddAuthor controller takes nullable id of the author.

So when u have null id, you can redirect to an action to create an author, that will later return an id of the author that was created and then add it to the book.

And when you do pass the id it will just add the author to the specified book.

0

精彩评论

暂无评论...
验证码 换一张
取 消