-1

I have the following jQuery-code that make a POST:

$.ajax({
                url: 'http://localhost:65148/Home/BandRegister',
                data: formData,
                type: "POST",
                processData: false,
                contentType: false,
                success: function (data, textStatus, XMLHttpRequest) {
                    //location = data.url;
                    console.log(data);
                },
                error: function (data, textStatus, XMLHttpRequest) {
                    console.log(data);
                }
            });

I handle the post In the following controller:

    if (BandProfile != null)
    {
        userManager.AddToRole(UserId, "Band");
        return Json(new { url = Url.Action("Index", "Home", new { model = BandProfile }) }, JsonRequestBehavior.AllowGet);
    }

In the controller, I want to redirect to a new controller and view, and pass the model with me. How can I do this with jQuery?

Or should I just get the information from the database and make a new model object when I have redirected to the new controller? Thus skip to pass the model with me?

Here Is my HTML:

Firstname: Lastname: Birth: Profile picture: Genre(loop out from table in database): Lägg till flera alternativ här. Precis som när man ska tagga något

Create

I am capturing the input values with jquery.

Bryan
  • 3,421
  • 8
  • 37
  • 77
  • Is there a reason you want to do this in jQuery as opposed to in C#? – Professor of programming Mar 06 '16 at 22:20
  • @Bonner: Yes. Im doing a post for registration with jQuery to C#. – Bryan Mar 06 '16 at 22:22
  • I'm still not clear on what you are trying to do. In trying to work out what you are doing are you redirecting the webpage when a registration is submitted, whether it be successful or not, or something else? – Professor of programming Mar 06 '16 at 22:26
  • @Bonner: Yes. Read my code. If BandProfile is not null, I want to redirect to a new controller and view. But because the POST Is made by jQuery, I must handle the request back to client. – Bryan Mar 06 '16 at 22:34
  • I am trying to establish why you want to perform the redirect in jQuery when you can do it on the server, saying you want to perform the redirect in jQuery as opposed to on the server because you are `doing a post for registration with jQuery to C#` isn't a reason, it is simply stating what you are doing. When you check to see if BandProfile is not null within that block you can tell C# to perform a redirect which will have the same effect as doing so in jQuery, if you are happy doing the redirect in C# I will post an answer using this method. – Professor of programming Mar 06 '16 at 22:40
  • @Bonner: No, It will not have the same effect as doing It in jQuery. You must handle the request back to the client after the post have been made and do the redirection with jQuery. My problem Is that I want to redirect with a model-object. So how do I return the model back to jQuery and then do the redirect? As you can see, I have tried to return a Url.Action, which works fine, but I want to attach my BandProfile-model. – Bryan Mar 06 '16 at 22:43
  • Can you include the code that generates your form for me please? – Professor of programming Mar 06 '16 at 22:51
  • @Bonner: Check my updated question. – Bryan Mar 06 '16 at 22:56
  • Was hoping for how you generate the form element itself mainly, are you using a form element or are you using the MVC framework HTML helpers? – Professor of programming Mar 06 '16 at 22:59
  • @Bonner: I am not sure that you are experienced enough to help me. As I wrote, I am capturing the field data with jquery. And no, no helpers at all IN this case. You can read more about redirection with jquery and asp.net here: http://stackoverflow.com/questions/3140373/post-data-with-jquery-and-redirect-to-another-action – Bryan Mar 06 '16 at 23:02
  • Check my git commit history for the ASP.NET MVC Framework, if you don't provide enough information we can't provide an answer, at the moment I suspect you are the one lacking the experience as what you are trying to do is completely wrong and without all the information I need I'm unwilling to provide an answer. – Professor of programming Mar 06 '16 at 23:03
  • @Bonner: I don't know how to be any clearer: I make a Post with Jquery to my action in my controller In the asp.net. In my action, Where I Post to with Jquery, I save the data in the database. After the data has been saved, I want to do a redirect to a new controller and pass the model with me. How can I do this with jQuery? I must do It with Jquery because Im posting with Jquery. – Bryan Mar 06 '16 at 23:06

1 Answers1

0

You can forward the request on the server. The client will not notice that,so jquery does not mattet for this.

I dont know how to do a forward on .net. but its part of the servlet spec so should be possible.