-
May 23rd, 2010, 10:41 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Redirect, passing model class
I got a ContactForm view model class (name,email,subject message).
In the contact "get" action method, I create a new instance of this class, and render my view with it.
Now, what I want to do in the contact "post" action method (if modelstate is valid and the message have been sent successfully) is to display a view (strongly typed using the ContactFormViewModel) and simple say "The following message was sent successfully:" and a "DisplayForModel()".
However it seems one cannot do a redirecttoaction (or route) passing a model (which the action method returning the last view will need).
I can return a View, and pass the model, but that break the PRG pattern (F5 submit the message again).
Probably just missing something simple, but figured I'd post.
-
May 23rd, 2010, 11:30 AM
#2
Thread Starter
Hyperactive Member
Re: Redirect, passing model class
Hmmm. Recalled you can do this using MvcContrib.
So I went and added a reference and do a call like this (that worked in an older MVC 1 project)
Code:
// return this.RedirectToAction(x => x.ContactSuccess(model));
return this.RedirectToAction<PublicController>(x => x.ContactSuccess(model));
Now, when I hit that line I get told that Mvc's dll cannot be found. Uuurgh..this is an MVC 2 project created in VS 2010!
Server Error in '/' Application.
Could not load file or assembly 'Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 32: {
Line 33: // return this.RedirectToAction(x => x.ContactSuccess(model));
Line 34: return this.RedirectToAction<PublicController>(x => x.ContactSuccess(model));
Line 35: }
Line 36: return View(model);
-
May 23rd, 2010, 11:44 AM
#3
Thread Starter
Hyperactive Member
Re: Redirect, passing model class
My idiotic reading!
System.Web.MVC != Microsoft.Web.MVC
-
May 23rd, 2010, 10:56 PM
#4
Thread Starter
Hyperactive Member
Re: Redirect, passing model class
Abandoning this way.
RedirectToAction issue a GET request, so even if that work I'll b having a terribly ugly url.
Will just alter my idea and not pass a model.
-
May 24th, 2010, 03:27 AM
#5
Re: Redirect, passing model class
I'm a bit lost at what the problem is? I thought you solved it?
-
May 24th, 2010, 03:34 AM
#6
Thread Starter
Hyperactive Member
Re: Redirect, passing model class
Never solved it the way I wanted it to be, no. Just let it go and try find a better approach.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|