You must Sign In to post a response.
  • Category: ASP.Net MVC

    Multiple actions in single view

    I am new in MVC.
    I have created 1 sample form with 2 textbox, 1 dropdownlist, 1 button to search data and grid view to bind data.

    I have written 2 actions in controller "Employee".
    1 action which is used for dropdown binding, which is called at the time of loading,
    but at the same time, without calling method of grid view binding, html code is rendering, so that, it gives error like "You must bind datasource before doing this operation".
    Later I added condition, "if (ViewBag.dt != null)", then only grid view binding related html render.
    But now, whenever I click on submit, dropdown binding html is rendering without calling method of dropdown binding. Please give proper way of doing this kind of functionality.
  • #767231
    Add IsPostBack condition on page load:

    if (!IsPostBack)
    //Place the code here for loading dropdownlist

    Or call javascript function on button click and return false from it, so that post back will not occur.

    OnClientClick="return StopPostBack();"

    function StopPostBackL()
    return false;

  • Sign In to post your comments