JustJohn
JustJohn

Reputation: 1460

I have no luck passing multiple values to a redirected Razor Page

I can't seem to pass a new model I make OnPost. So I am trying to just pass the route values.

I can return RedirectToPage("ValidateCommand") but the model I build doesn't get passed:

 var paypal = new PayPalModel();

paypal.cmd = "_xclick";
paypal.item_number = "xyz";
paypal.item_name = "Course Name Here";
paypal.amount = "1";
paypal.currency_code = "USD";
paypal.no_shipping = 1;

paypal.actionURL = "https://www.paypal.com/cgi-bin/webscr";
paypal.business = "[email protected]";
paypal.cancel_return = "http://localhost:xxx/Misc/cancel";
paypal.@return = "http://localhost:xxx/Misc/thankyou";
paypal.notify_url = "http://localhost:xxx/Misc/done";

So I was thinking I would pass all the above values as @page directives (not sure that is what it's called).

return RedirectToPage("ValidateCommand", new {cmd = "_xclick", item_number = "xyz", item_name = "Course Name Here", amount = "1", currency_code="USD", no_shipping=1, actionURL = "https://www.paypal.com/cgi-bin/webscr", business = "[email protected]", cancel_return = "http://localhost:50061/Misc/cancel", @return = "http://localhost:50061/Misc/thankyou", notify_url = "http://localhost:50061/Misc/done" });

And in my "ValidateCommand.cshtml" I have this I took the Model example from an MVC app I have that works.

@page "{cmd}/{item_number}/{amount}/{currency_code}/{no_shipping}/{acitonURL}/{business}/{cancel_return}/{@return}/{notify_url}"

@model OESAC.Models.PayPalModel

<form id="hiddenform" [email protected]["actionURL"]>
   @Html.HiddenFor(model => model.cmd)
        @Html.HiddenFor(model => model.business)
        @Html.HiddenFor(model => model.no_shipping)
        @Html.HiddenFor(model => model.@return)
        @Html.HiddenFor(model => model.cancel_return)
        @Html.HiddenFor(model => model.notify_url)
        @Html.HiddenFor(model => model.currency_code)
        @Html.HiddenFor(model => model.item_name)
        @Html.HiddenFor(model => model.amount)
        @Html.HiddenFor(model => model.item_number)

    <input hidden value="@RouteData.Values["cmd"])" />
    <input hidden value="@RouteData.Values["business"])" />
    <input hidden value="@RouteData.Values["no_shipping"])" />

</form>

The PayPalModel is left over from my MVC app. But in my Razor Pages it doesn't exist. I was hoping I could replace the model => model.item_number with my new model or route or querystring values. Anything. These values get sent to PayPal for user to make payment. This works for an MVC app I have and also a vb.net web forms application.

This is the error I get: "InvalidOperationException: No page named 'ValidateCommand' matches the supplied values."

Upvotes: 0

Views: 321

Answers (1)

Mike Brind
Mike Brind

Reputation: 30065

Double check the supplied parameter values you are passing with the placeholder names in the route template. I can see at least one (item_name) missing from the route template, and one where the spelling doesn't match (actionUrl). Also, you don't need to prefix return with an @ sign in the route template. You only need to do that in C# code.

Upvotes: 1

Related Questions