将带有location.href的参数传递给操作。 [英] Passing parameter with location.href to the action.

查看:693
本文介绍了将带有location.href的参数传递给操作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从location.href将参数传递给控制器​​。



但链接没有达成动作。 location.href似乎没问题。



我的尝试:



我正在尝试的代码是



触发jqeury代码的按钮

I am trying to pass the parameters to the controller from location.href.

but link is not hitting the action. location.href seems ok .

What I have tried:

The code i am trying is

the buttion triggering the jqeury code

<button id="getPrice" data-id="" class="btn btn-danger" data-dismiss="modal">GetPrice</button>





实际的jquery代码





the actual jquery code

<pre lang="HTML"> $('#getPrice').click(function () {
                var discountAmount = $('#lblDiscountAmount').text();
                var productId = $(this).parent('td').parent('tr').attr('data-productid')
                alert(productId);
                alert(discountAmount);
                //if (!discountAmount) { return; }

                location.href = "Products/helloPrice?ProductId=" + productId;
               // This is not invoking the action method.

            });



我调试代码时没有触发此动作方法,错误是资源无法找到,以及如何传递addtional参数


this actionmethod is not triggered when i debug the code and error is resource cant be found and also how to pass addtional parameters

public ActionResult helloPrice(int productid)
      {

          //String a = "produt ID id " + ProductId + "and priec" + ProductPrice;
          //string a = "hi";
          //ViewBag.MyString = "produt ID id " + ProductId +"yes";
          return View();
      }





以及如何使用



and also how it can be done with

@Html.ActionLink("HelloPrice", "helloPrice", new { id = item.Id }  , new {@class="myClass"}) 





@class =myClass用于传递附加参数discountAmount



@class ="myClass" is used to pass additional parameter discountAmount

推荐答案

('#getPrice')。click(function(){
var discountAmount =
('#getPrice').click(function () { var discountAmount =


('#lblDiscountAmount')。text();
var productId =
('#lblDiscountAmount').text(); var productId =


(this).parent('td' ).parent('tr')。attr('data-productid')
alert(productId);
alert(discountAmount);
// if(!discountAmount){return;}

location.href =Products / helloPrice?ProductId =+ productId;
//这不是调用action方法。

});
(this).parent('td').parent('tr').attr('data-productid') alert(productId); alert(discountAmount); //if (!discountAmount) { return; } location.href = "Products/helloPrice?ProductId=" + productId; // This is not invoking the action method. });



当我调试时,不会触发此actionmethod代码和错误是资源无法找到,以及如何传递addtional参数


this actionmethod is not triggered when i debug the code and error is resource cant be found and also how to pass addtional parameters

public ActionResult helloPrice(int productid)
      {

          //String a = "produt ID id " + ProductId + "and priec" + ProductPrice;
          //string a = "hi";
          //ViewBag.MyString = "produt ID id " + ProductId +"yes";
          return View();
      }





以及如何使用



and also how it can be done with

@Html.ActionLink("HelloPrice", "helloPrice", new { id = item.Id }  , new {@class="myClass"}) 





@class =myClass用于传递附加参数discountAmount



@class ="myClass" is used to pass additional parameter discountAmount


这篇关于将带有location.href的参数传递给操作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆