将已检索的数据从一个控制器操作方法传递到另一个控制器操作方法 [英] Passing the retrived data from one controller action method to the other controller action method
问题描述
我通过操作方法 GetDis 检索折扣价并在视图中显示。
我想通过折扣价格值到另一个行动方法。所以我可以在控制器中使用它。如何将视图值传递给控制器。
I retrieved the discounted price via action method GetDis and display it in the view.
I want to pass the discounted price value to the other action method . so i can use it in the controller . How can i pass the value for view to the controller.
<pre>@foreach (var item in Model) {
<tr data-productid="@item.Id">
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductPrice, new { @id = "check" })
</td>
<td>
@Html.DropDownList("Status", new List<SelectListItem>
{
new SelectListItem{ Text="Student Discount", Value = "1" },
new SelectListItem{ Text="Loyalty Discount", Value = "0" }
}, "Please select discount", new { @class="ddlStatus" })
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
<div class="clearfix">
<div class="pull-right">
<label>Discount: <span id="lblDiscountAmount"></span></label>
</div>
</div>
@section scripts{
<script>
$('.ddlStatus').change(function () {
var val = $(this).val();
var productId = $(this).parent('td').parent('tr').attr('data-productid')
ChangeDis(val, productId);
});
function ChangeDis(val, productId) {
$.ajax({
url: '/Products/GetDis',
data: {
discount: val,
productId : productId
},
success: function (data) {
$('#lblDiscountAmount').text(data);
}
});
}
</script>
}
这个折扣价格附加在
This discounted price value is appended on the
<label>Discount: <span id="lblDiscountAmount"></span></label>
我想发送它在一些动作方法中的另一个控制器。我怎么能这样做。
我尝试过:
我在视图中显示了折扣价。并希望将discorted price的值传递给action方法中的另一个控制器。
I want to send it to the another controller in some action method. how can i do it.
What I have tried:
I have displayed the discounted price in the view . and want to pass the value of discouted price to another controller in a action method.
推荐答案
(' 。ddlStatus')。change( function (){
var val =
('.ddlStatus').change(function () { var val =
( this )。val();
var productId =
(this).val(); var productId =
( this )。parent(' td')。parent(' tr')。attr(' data-productid')
ChangeDis(val,productId);
});
function ChangeDis(val,productId){
(this).parent('td').parent('tr').attr('data-productid') ChangeDis(val, productId); }); function ChangeDis(val, productId) {
这篇关于将已检索的数据从一个控制器操作方法传递到另一个控制器操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!