Results 1 to 6 of 6

Thread: [RESOLVED] Redirect, passing model class

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Resolved [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.


  2. #2

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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);


  3. #3

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: Redirect, passing model class

    My idiotic reading!
    System.Web.MVC != Microsoft.Web.MVC


  4. #4

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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.


  5. #5
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Redirect, passing model class

    I'm a bit lost at what the problem is? I thought you solved it?

  6. #6

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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
  •  



Click Here to Expand Forum to Full Width