Asp.net MVC获取文本框的值在View [英] Asp.net MVC Get Textbox Value In View

查看:206
本文介绍了Asp.net MVC获取文本框的值在View的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个输入框

<input type='text' name='quantity' value='1'/>

如何访问它的价值?

How do I access the value of it?

@Html.ActionLink("Add to cart", "AddToCart", "ShoppingCart", new { id = Model.ProductID, quantity = IWANTTHEVALUEHERE } "")

感谢。

推荐答案

试试这个:

<input type='text' id='qty' name='quantity' value='1'/>

@Html.ActionLink("Add to cart", "AddToCart", "ShoppingCart", new { id = "link" })

和添加在你的JavaScript有这样的:

and add have this in your javascript:

$('#link').click(function () {
  var id = '@Model.ProductID';
  var quantity = $('#qty').val(); 
  window.location = '@Url.Action("Action", "Controller")?id=' + id + '&quantity=' + quantity;
})

这篇关于Asp.net MVC获取文本框的值在View的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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