Jquery conditionals, window locations, and viewdata. Oh my!
- by John Stuart
I have one last thing left on a project and its a doozy. Not only is this my first web application, but its the first app i used Jquery, CSS and MVC. I have no idea on how to proceed with this.
What i am trying to do is:
In my controller, a waste item is validated, and based on the results one of these things can happen. The validation is completed, nothing bad happens, which sets ViewData["FailedWasteId"] to -9999. Its a new waste item and the validation did not pass, which sets ViewData["FailedWasteId"] to 0. Its an existing waste item and the validation did not pass, which sets ViewData["FailedWasteId"] to the id of the waste item.
This ViewData["FailedWasteId"] is set on page load using
<%=Html.Hidden("wFailId", int.Parse(ViewData["WasteFailID"].ToString()))%>
When the validations do not pass, then the page zooms (by window.location) to an invisible div, opens the invisible div etc. Hopefully my intentions are clear with this poor attempt at jquery.
The new waste div is and the existing item divs are dynamically generated (this i know works) "
So my question here is... Help? I cant even get the data to parse correctly, nor can i even get the conditionals to work. And since this happens after post, i cant get firebug to help my step through the debugger, as the script isnt loaded yet.
$(document).ready(function () {
var wasteId = parseInt($('#wFailId').text());
if (wasteId == -9999) {
//No Issue
}
else if (wasteId < 0) {
//Waste not saved to database
}
else if (wasteId == 0) {
//New Waste
window.location = '#0';
$('.editPanel').hide();
$('#GeneratedWasteGrid:first').before(newRow);
$('.editPanel').appendTo('#edit-panel-row').slideDown('slow');
}
else if (wasteId > 0) {
//Waste saved to database
}
});