Hidden Field

(JQUERY)


Hi,
In this article i discuss about how to manipulate the hidden field using jquery.

View:-

@{
    ViewBag.Title = "Hiddenfield";
}

<script src="../../Scripts/jquery-1.7.1.js"></script>

<h2>hidden field</h2>

<input type="hidden" name="hdnfld_message"  data-message="@ViewBag.message" />

<input type="button" id="btn_getmessage" value="Get Message" />

<script type="text/javascript">

    $(function () {

        $('#btn_getmessage').click(function () {

            alert($('input[name="hdnfld_message"]').data('message'));
        });
    });

</script>

Controller:-

  public ActionResult Hiddenfield()
        {
            try
            {
                ViewBag.message = "Welcome to ASP.NET MVC";

                return View();
            }
            catch (Exception)
            { }
            return null;
        }

Image

Ratings


Average Rating: 5.00 by 11 users
Giri Prasad
1/30/2016
1/30/2016
Download PDF

Comments






John

It saved my day


Tapan

Helpful


Tapan

Helpful