Click here to Skip to main content
15,357,966 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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);
Updated 27-Apr-17 5:00am

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 #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

    // I'm using the submit event of the form to run GetId, you
    // can use a different method if desired
            // pass your proper tempid
you can use ajax as well.
First add ajax CDN


<input type="submit" value="submit data" onClick="redirectUrl(data1,data2)">


you can also take data from element by using jquery id selector<a href="">jQuery Selectors</a>[<a href="" target="_blank" title="New Window">^</a>].once you have data pass
it in ajax call

<pre>&lt;script type="text/javascript"></pre>

function redirectUrl(parameter1, parameter2) {
var URL = url + '/' + parameter + '?EmpId=' + parameter2;

url: URL,
type: "GET",
success: function (data) {
error: function (data) { alert("error in redirectUrl()!!"); $('#divLoding').hide(); }


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900