-2

I want pass value to ActionResult but Dont want to use Querystring and session because value type is guid so dont want to display in URL.

function ViewDetail(ele) {
    var Id = $(ele).attr("OrderID");
    @TempData["OrderID"] = Id;    
}
SPnL
  • 338
  • 4
  • 15
  • 4
    You cant (on the client side). `TempData` is a server side value and javascript is client side. You would need to use ajax to post the value to a controller method and set the value, but that would make no sense. What are you trying to achieve? –  Jun 21 '16 at 13:41
  • 1
    is there a particular reason you dont want to show guid in query string? – JamieD77 Jun 21 '16 at 14:07
  • 2
    First, `TempData` *is* the session. It's the same thing. If you don't want to use the session (which you shouldn't), then you shouldn't want to use `TempData` for this either. Second, if you don't want to expose the GUID, then pick some other unique identifier on the order and use that instead. That's your only choice though. A particular order is a unique resource and you need something like an id *somewhere* in the URL to identify that unique resource. – Chris Pratt Jun 21 '16 at 16:07

2 Answers2

2

Basically you can't this way , you are trying to assign server side object to client side data.

However you can do that using Ajax if you write an Ajax action that will assign the data to the tempdata and call that action from the client side by Ajax

Bassem
  • 54
  • 3
0

Ajax code:

function ViewDetail(ele) {
    var Id = $(ele).attr("OrderID");
    $.ajax({
                    type: "POST",
                    cache: false,
                    async: false,
                    url: '@Url.Action("actionname", "controllername")',
                    dataType: "json",
                    data: { Id: Id },
                    failure: function (jqXHR, exception) {
                        if (jqXHR.status === 0) {
                            alert('Not connect.\n Verify Network.');
                        } else if (jqXHR.status == 404) {
                            alert('Requested page not found. [404]');
                        } else if (jqXHR.status == 500) {
                            alert('Internal Server Error [500].');
                        } else if (exception === 'parsererror') {
                            alert('Requested JSON parse failed.');
                        } else if (exception === 'timeout') {
                            alert('Time out error.');
                        } else if (exception === 'abort') {
                            alert('Ajax request aborted.');
                        } else {
                            alert('Uncaught Error.\n' + jqXHR.responseText);
                        }
                    }
                });  
}

Hope it helps!

Nagaraj Raveendran
  • 1,150
  • 15
  • 23