0

I am developing MVC application. I have written a JQuery in view. but confused about the passing the parameter... How to write it ?

View Code------

  function ValidateSanctionAmount()
    {

      var amt1=$('#Amount1').val();
      var amt2=$('#Amount2').val();

  var url1 = '@Url.Action("checkPOAmountsValidations", "PaymentAdviceController", new { POId : "a", SanctionedAmt : "b" })';
                        url1 = url1.replace("a",amt1);
                        url1 = url1.replace("b",amt1);

                        url1 = url1.replace("sanctionedAmount",param1);

                        $.ajax({
                            url: url1,
                            type: "GET",
                            success: function (Data) {
                                $('#divNewInvoice').append(Data);
                            }
                        });

Controller Code-----

   public JsonResult checkPOAmountsValidations(int POId,double SanctionedAmt)
          {
                var oPurchaseOrderHelper = new PurchaseOrderHelper();
                bool b;
                int POId1 =POId;
                double SanctionedAmt1 = SanctionedAmt;

                b = oPurchaseOrderHelper.GetAmountsSumForValidation(POId1, SanctionedAmt1);

                if (b == true)
                {
                    return Json(true);
                }
                else
                {
                    return Json(false);
                }

          }

------ Code in View enter image description here

------Code in Controller

enter image description here

3
  • Can you post the code for the controller please? Commented Jun 28, 2013 at 8:28
  • Image is not getting load, please provide text Commented Jun 28, 2013 at 9:20
  • I have updated, check now... Commented Jun 28, 2013 at 9:22

1 Answer 1

2

Update: Since you are using ajax do this and you don't have to do url1.replace

var url1 = '@Url.Action("checkPOAmountsValidations", "PaymentAdviceController")';
$.ajax({
    url: url1,
    data : JSON.stringify({ POId : amt1, SanctionedAmt: amt2 }),
    dataType : "JSON",
    type: "GET",
    success: function (Data) {
        $('#divNewInvoice').append(Data);
    }
});

Old:

try this, JavaScript doesn't execute when generating the action URL.

function ValidateSanctionAmount()
{
    var amt1=$('#Amount1').val();
    var amt2=$('#Amount2').val();

    var url1 = '@Url.Action("check", "controller1", new { param1= "-1", param2= "-1" })';
    url1 = url1.replace("-1",amt1);
    url1 = url1.replace("-2",amt2);
}

Controller method:

public class controller1: Controller
{
    public ActionResult check(double param1, double param2)
    {
        //Do whatever
        return View();
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I want to pass amt1, amt2 to method
what is Paeam1 and Param2 ? where it should be declare ? showing error in the code Param1,Param2 does not exist in current context

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.