Monday, January 16, 2012

How to recursively disable all of elements inside a div by Javascript?

<script type="text/javascript">

    $('#readonlydiv').ready(function () {

        RecursiveDisable(document.getElementById("readonlydiv"));

    });



    function RecursiveDisable(element) {

        try {

            element.disabled = element.disabled ? false : true;

        }

        catch (E) {

        }

        if (element.childNodes && element.childNodes.length > 0) {

            for (var x = 0; x < element.childNodes.length; x++) {

                RecursiveDisable(element.childNodes[x]);

            }

        }

    }

How to handle multiple buttons in one form in ASP.NET MVC?


1.      Razor view:

@using (Html.BeginForm())

{

    <fieldset>

        <legend>Edit </legend>

        <div class="editor-label">

            @Html.LabelFor(model => model.ID)

        </div>

        <p>

            <input name ="button" type="submit" value="Save" />

            <input name ="button" type="submit" value="Reject" />

            <input name ="button" type="submit" value="Accept" />

            <input name ="button" type="submit" value="Complete" />

        </p>

    </fieldset>

}



2.  Controller

        [HttpPost]

        public ActionResult Edit(string button)

        {

            switch (button)

            {

                case "Save":

                    break;

            }

            return RedirectToAction("Index");

        }