Jquery conditionals, window locations, and viewdata. Oh my!

Posted by John Stuart on Stack Overflow See other posts from Stack Overflow or by John Stuart
Published on 2011-01-15T07:27:16Z Indexed on 2011/01/15 7:53 UTC
Read the original article Hit count: 149

Filed under:

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
            }
        });

© Stack Overflow or respective owner

Related posts about asp.net-mvc