0

I want to pass data from Textbox value to the controller. The Textbox Value its string and on the controller, it must be converted to double. But I seem to fail on the presented code below. I don't know why the code does not work.

===VIEW CODE===

 @using (Html.BeginForm("OnceOff"))
  {
    <div class="container">
     <div class="bg hidden-sm"></div>

      <div class="row">
     <div class="col">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title">Once-Off Payment</h3>
                </div>

                <div class="panel-body">

                    <input type="text" id="smsbundles" name="smsbundles" value="50" />

                </div>
                <div class="text-right">
                    @Html.ActionLink("Buy Now", "OnceOff", "Home", new { area = "" }, new { @class = "btn btn-block btn-success" })

                </div>
            </div>


        </div>

     </div> 
  </div>
           }

===CONTROLLER===

   public ActionResult OnceOff(string smsbundles)
    {
        double bundle = Convert.ToDouble(smsbundles);
        var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

        // Merchant Details
        onceOffRequest.merchant_id = this.payFastSettings.MerchantId;
        onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
        onceOffRequest.return_url = this.payFastSettings.ReturnUrl;
        onceOffRequest.cancel_url = this.payFastSettings.CancelUrl;
        onceOffRequest.notify_url = this.payFastSettings.NotifyUrl;

        // Buyer Details
        onceOffRequest.email_address = "";

        // Transaction Details
        onceOffRequest.m_payment_id = "***";
        onceOffRequest.amount = bundle;  //30 or 50
        onceOffRequest.item_name = "Once off option";
        onceOffRequest.item_description = "Some details about the once off payment";

        // Transaction Options
        onceOffRequest.email_confirmation = true;
        onceOffRequest.confirmation_address = "****";

        var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

        return Redirect(redirectUrl);
    }

1 Answer 1

1

Your input smsbundles is an input element inside a form. You are using ActionLink helper, that generates <a> element that does not submit the form. That's the reason your controller action code is called with a null value of smsbundles.

Replace you ActionLink to a regular submit button:

<input type="submit" value="Buy Now" class="btn btn-block btn-success" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.