Click here to Skip to main content
15,904,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
Controller:
[HttpPost]
        public ActionResult View1(string SelectedVal)
        {
            IList<string> split1;
            split1 = SelectedVal.Split(new[] { '\n' });

            ViewBag.Code = split1[0];
            ViewBag.Desc = split1[2];
            
            return View(); 
        }
JS:
<script type="text/javascript">
    function onClick(e) {

        //alert(e.item[0].outerText)
        var SelectedVal = e.item[0].outerText;
        //alert(SelectedVal)
        $.ajax({
            url: "/TTSCancel/View1",
            data: JSON.stringify({ SelectedVal: SelectedVal }),
            dataType: "json",
            type: "POST",
            contentType: 'application/json; charset=utf-8'
        });
    }
</script>
View:
@model List<TTS.Models.CancelModel>
<h3>Code :</h3>
<label class="labelclass">@ViewBag.Code</label>
<br />
<h3>Decsription :</h3>
<label class="labelclass">@ViewBag.Desc</label>
<br />
Posted
Updated 19-Jan-16 22:29pm
v4
Comments
Sri Nivas (Vasu) 20-Jan-16 5:50am    
What exactly you want to do onClick() method?
Just it will call ajax method. It will not do any redirect.
If you want redirect you can use location.href = "http://domain.com/TTSCancel/View1";

1 solution

All your code is doing is making a request to the url for the action. The request will return the html for the View, but you're not doing anything with the result, just ignoring it. If you want to actually redirect the user to that view you shouldn't use ajax, just use a normal form. If you want a link-type process rather than a form submit button you can use your js to submit the form on the click of your link. If you don't want to direct the user away but to simply show the html on your page somewhere then you need to use the "success" event of your ajax call to inject the html somewhere into your page.
 
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