The problem you are facing is that you are trying to enclose @ ViewBag.fromDateForEditMode in quotation marks. When you do this in your jquery function, it causes the browser jquery processor to evaluate it as a literal string when the script is called, rather than letting your razor engine evaluate the contents of the ViewBag while the page is loading.
To work around this problem, use:
var startDate = new Date (@ ViewBag.StartDate.Year.ToString (), @ ViewBag.StartDate.Month.ToString () -1, @ ViewBag.StartDate.Day.ToString ());
This will allow the razor engine to evaluate the contents of the ViewBag before executing the jquery script.
source share