Home > OS >  how to make this asp.net code redirect to a different page after submit
how to make this asp.net code redirect to a different page after submit

Time:06-10

First and foremost I do not have access to the controller part, the website it's already compiled and I do not have the source just the .dll

        @using (Html.BeginForm("Details", "Shop", FormMethod.Post, new { role = "form"}))
        {
<p>Select Character:</p>
            if (Model.Chars != null && Model.Chars.Count > 0)
            {
                @Html.AntiForgeryToken()
                @Html.ValidationSummary("", new {@class = "text-danger"})
                if (Request.IsAuthenticated)
                {

                    @Html.HiddenFor(x => Model.Guid, Model.Guid)

                    for (var index = 0; index < Model.Chars.Count; index  )
                    {
                        var charInfo = Model.Chars[index];
                        var chdata = charInfo.Name   " (lv."   charInfo.Level   ")";

                        if (index == 0)
                        {
                            <div>
                                @Html.RadioButtonFor((x) => Model.CharName, charInfo.Name, new {Checked = "checked"}) @chdata
                            </div>
                        }
                        else
                        {
                            <div>
                                @Html.RadioButtonFor((x) => Model.CharName, charInfo.Name) @chdata
                            </div>
                        }
                    }
                }
<p/>
                <input type="submit"  value="Confirm Purchase"/>
            }
            else if (Model.Chars == null)
            {
                <h4  style="color: red">To purchase items, you must first log in to your account</h4>
            }
            else
            {
                <h4  style="color: red">You cannot buy items, you don't have any characters in your account</h4>
            }
        }

normally it should redirect to Shop when it receives the notification BuyOk as stated in _Layout.cshtml but it doesn't.

    @{
        var messages = ViewBag.Errors as List<ViewError>;
        var notifications = ViewBag.Notifications as List<ViewNotification>;
    }

    @if (notifications != null && notifications.Count > 0)
    {
        <div  style="background: #00ff00">
            @foreach (var message in notifications)
            {
                <span  onclick="this.parentElement.style.display = 'none';">&times;</span>

                string msg;

                switch (message)
                {
                    case ViewNotification.BuyOk:
                        msg = "Purchase complete";
                        break;
                    case ViewNotification.ChangePwdOk:
                        msg = "Password change request successful, description sent to your email";
                        break;
                    case ViewNotification.ChangePwdSuccess:
                        msg = "Password Changed";
                        break;
                    case ViewNotification.ChangeEmailSuccess:
                        msg = "Email has been changed";
                        break;
                    default:
                        msg = "Unknown notification";
                        break;
                }

                @msg
            }
        </div>
    }

There are no errors but case ViewNotification.BuyOk: it's not triggered therefore after pressing the submit button the action is completed without any errors but it doesn't redirect to Shop

What I wanna do is to redirect to Shop after I press Confirm Purchase

PS: I only own the compiled code, I tried to decompile with several decompiling software but so far no luck and I cannot see the real controller nor can I edit it

I hope someone can help me with this issue, Thank you

CodePudding user response:

on completion, the website is redirected and isOk=False or isOk=True was added at the end of the URL. I used javascript to create a redirection if isOk=True exists in the URL. Thank you

  • Related