如何在按钮单击时使用2个参数重定向到控制器方法 [英] How to redirect to controller method with 2 parameters on button click
问题描述
我有一个预览按钮。点击预览按钮我想显示视图。但是点击按钮我已经传递了两个参数作为查询字符串。但我不想在url中显示这些参数。另一种方式是什么?
Plz帮助我..
我尝试了什么:
函数GetId(tempid){
var ProductId = getParameterByName('productid');
var url =../Template/GetDataForTemplete?TempleteID=+ tempid +& ProductID =+ ProductId;
window.location.href = url;
}
public ActionResult GetDataForTemplete(int templeteIDint ProductID)
{
EventViewModel model = new EventViewModel();
model = GetData(ProductID);
if(TempleteID == 1)
{
返回查看(Templete1,型号);
}
}
I have a preview button. on click of preview button I want to display view. but on clicking button I have pass two parameters as querystring. But I dont want to display that parameters in url. what is another way?
Plz help me..
What I have tried:
function GetId (tempid) {
var ProductId = getParameterByName('productid');
var url = "../Template/GetDataForTemplete?TempleteID=" + tempid + "&ProductID=" +ProductId;
window.location.href = url;
}
public ActionResult GetDataForTemplete(int templeteIDint ProductID)
{
EventViewModel model = new EventViewModel();
model = GetData(ProductID);
if (TempleteID == 1)
{
return View("Templete1", model);
}
}
推荐答案
使用表格
Use a form
@using (Html.BeginForm("GetDataForTemplete", "Home", FormMethod.Post, new { id = "myForm" }))
{
<input type="hidden" name="templeteID" id="templeteID" />
<input type="hidden" name="ProductID" id="ProductID" />
<input type="submit" value="Submit" />
}
<script type="text/javascript">
function GetId(tempid) {
// set the form variables to whatever you want
(#myForm #templeteID)。val(tempid);
("#myForm #templeteID").val(tempid);
(#myForm #ProductID)。val(2);
//这个代码是从表单提交中调用的,所以表单是
//无论如何都要提交。如果您的代码是通过点击事件
//调用的,则您需要提交以下表格
//
("#myForm #ProductID").val(2); // this code is getting called from the form submit so the form is // being submitted anyway. If your code is called from a click event // you'll need to submit the form as below //
这篇关于如何在按钮单击时使用2个参数重定向到控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!