javascript - MVC: Get URL of Method When Using Routing -
i found this tutorial on how build cascading dropdowns in mvc razor syntax. followed tutorial , got working in it's own project. trying port on actual project, getting error when first dropdown changed. per script, alert pops says:
failed retrieve states: [object object] i have no idea [object object] means. guess error has url:
url: '@url.action("getstates") but that's guess. major difference between example project , real project real project uses routing url here's entire script:
<script src="~/scripts/jquery-1.10.2.js" type="text/javascript"></script> <script src="~/scripts/jquery-1.10.2.min.js" type="text/javascript"</script> <script type="text/javascript"> $(document).ready(function () { //dropdownlist selectedchange event $("#country").change(function () { $("#state").empty(); $.ajax({ type: 'post', url: '@url.action("getstates")', // calling json method datatype: 'json', data: { id: $("#country").val() }, // here value of selected country , passing same value input json method getstates. success: function (states) { // states contains json formatted list // of states passed controller $.each(states, function (i, state) { $("#state").append('<option value="' + state.value + '">' + state.text + '</option>'); // here adding option states }); }, error: function (ex) { alert('failed retrieve states: ' + ex); } }); return false; }) }); edit after:
while watching network traffic in chrome's developer tools, did in stand-alone project works, , saw entry title "getstates" , url: http://localhost:50266/customerfeedback/getstates.
i did again in actual project, , time see entry says "45/" url: http://localhost:65303/patientsatisfactionsurvey/45/.
i think confirms suspicion url problem. i'm going have play around figuring out how make url valid.
another edit:
on project works, if go to: http://localhost:50266/customerfeedback/getstates
i this:
server error in '/' application. request has been blocked because sensitive information disclosed third party web sites when used in request. allow requests, set jsonrequestbehavior allowget. this expected trying hit actual method. meaning, can go url of method. when try , same thing in project: http://localhost:65303/patientsatisfactionsurvey/getstates, loads page. that's because thinks "getstates" parameter, , not method.
i can not figure out url of method be!! dang routing getting in way....
routes.maproute( "patientsatisfactionsurvey", "patientsatisfactionsurvey/{apptid}/{*languagecode}", new { controller = "forms", action = "patientsatisfactionsurvey" }, namespaces: new[] { "gedc.controllers" } );
try changing @url.action("getstates") to:
@url.action("controllername", "actionname") probbaly @url.action("patientsatisfactionsurvey", "getstates") generate url ~/patientsatisfactionsurvey/getstates/5 5 id grabbing html element id of country.
Comments
Post a Comment