Click here to Skip to main content
15,885,914 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);
}
}
Posted
Updated 6-Mar-23 17:18pm

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
        //$("#myForm").submit();
    }

    // I'm using the submit event of the form to run GetId, you
    // can use a different method if desired
    $(document).ready(function(){
        $("#myForm").submit(function(e){
            // pass your proper tempid
            GetId(1);
        });
    });
</script>
 
Share this answer
 
you can use ajax as well.
First add ajax CDN

<body>

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


</body>

you can also take data from element by using jquery id selector<a href="https://www.w3schools.com/jquery/jquery_ref_selectors.asp">jQuery Selectors</a>[<a href="https://www.w3schools.com/jquery/jquery_ref_selectors.asp" 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;

$.ajax({
url: URL,
type: "GET",
success: function (data) {
$('#partialView').html(data);
Loading('close');
$('#divLoding').hide();
$('#partialView').show(500);
},
error: function (data) { alert("error in redirectUrl()!!"); $('#divLoding').hide(); }
});
}

<pre>&lt;/script></pre>
 
Share this answer
 

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