Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript onchange function changing - to / in url string?
    text
    copied!<p>I have an mvc3 web page that takes a url parameter representing a date, i.e dd-MM-yyyy</p> <pre><code>public ActionResult Calendar(string startDate, string UserId, string status, bool myPage = false) </code></pre> <p>I have a partial view within the calendar view which calls an onchange event whenever a ddl is changed, representing the status parameter within the method and is also passed into the url.</p> <p>My map route for the calendar view looks like this:</p> <pre><code>routes.MapRoute( "TimesheetCalendar", // Route name "Timesheet/Calendar/{startDate}/{UserId}", // URL with parameters new { controller = "Timesheet", action = "Calendar", UserId = UrlParameter.Optional } // Parameter defaults ); </code></pre> <p>And my javascript onchange event (called within a contained partial view) looks like this:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function () { $(".ddl").change(function () { changePage(); }); }); function changePage() { location.href = '@Url.Action("Calendar", "Controller", new { startDate = @ViewBag.startDate, UserId = (string)null })/' + '@ViewBag.userId' + '?status=' + $('#ControllerStatus').val() + '&amp;myPage=@ViewBag.myPage'; } </code></pre> <p></p> <p>In the calender get method in my controller, I set the Viewbag.startdate as <code>date.ToString(dd-MM-yyyy)</code>.</p> <p>It works fine, some of the time. And when I change the ddl status the page refreshed the calendar and partial view according to the status. Some of the time however (it seems whenever the week of my calendar is the current week), when I change the <em>ddl</em>, the browser redirects to a <code>404 error</code>, and rather than the date as <code>dd-MM-yyyy</code> in the url, it is showing as <code>dd/MM/yyyy</code> and thereby completely screwing up the url.</p> <p>I am new to javascript and have no idea why it would do this? I hope I have given enough info about my code. Anyone know why the string representing date would suddenly have its hyphens - changed to dashes/ ?</p> <p>Any help greatly appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload