I have a javascript function that works as I would like :
<script language="javascript" type="text/javascript">
function dofunction(dropdown) {
debugger;
for (i = 0; i < 194; i++) {
if (dropdown[i].selected == true) {
var Shrt_ttls = dropdown[i].value.toString();
$.ajax({
url: "/ProgramSummary/Details?titl=" + Shrt_ttls//,
//type: 'Post'
});
i = 195;
}
}
return;
}
</script>
The code redirects to the ProgramsummaryController to the Details method (in debug everything works fine and the correct value is passed to the method and the Details method looks like this
public ActionResult Details(string titl)
{
using (var dc = new USP_Select_TRP_ProgramSummary_wShortNameDataContext())
{
string shrt_titles = titl;
if (shrt_titles == null)
{
shrt_titles = "3DELRR";
}
return View(dc.usp_Select_TRP_ProgramSummary_wShortName(shrt_titles).Single());
}
}
The View is called and seems to be fine and returns to the _Layout.cshtml all seems fine but the Details View is not shown but instead the original Index view is shown. Where as if I use
@Html.ActionLink("Resource(s)", "Details", "ProgramSummary", new { titl = "3DELRR"})
The same events as before take place and instead of the Index view remaining the Details View appears. WHy does the first way not work?
You should use:
instead of Ajax, ajax is a request only in javascript, its not displayed by the browser unless you code it to.