8
Answers

Button Click event in MVC

srujana thallam

srujana thallam

10y
24.2k
1
Hello All,
 
I am working on MVC. 
I have a search criteria  and button.Bbased on search criteria after submit a button i want to display a grid in MVC. I am tying it but my button click is not going to method which i written in control.
 
Can any one please suggest how to write button click event in MVC.  its urget
 
Thanks 
Answers (8)
0
Shailesh Uke

Shailesh Uke

NA 691 9.7k 9y
In mvc no any event driven programming, on button click coll javascript function and coll proper action and getting data into list and using model data display on table using for loop
0
Srikanth Reddy

Srikanth Reddy

NA 237 8.4k 10y
try <input type=submit>
0
srujana thallam

srujana thallam

NA 76 86k 10y
I tried like this also

indie this i write all my code which i send previously to u

 @using (Html.BeginForm("BindGrid", "FTE", FormMethod.Get))
{                                //Action Method ,//Controler Name
//my code 
}

this is also not working for code
         
0
Srikanth Reddy

Srikanth Reddy

NA 237 8.4k 10y

Try this::

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { id = "FormId" }))
{
-------------------
----------------
Your Code
---------------
-----------
}
0
Anupam Singh

Anupam Singh

NA 5.8k 886.7k 10y
Hey dear ,

you have to specify action

replace this 
<form id="FTE_form" method="get" action="">

with
<form id="FTE_form" method="get" action="/your_controler_name/your_action_name">.

0
srujana thallam

srujana thallam

NA 76 86k 10y
HI 
I have sending the view of my page.i want to code for submit button in control page.

      <form id="FTE_form" method="get" action="">
        <fieldset>
            <legend>TransferLog</legend>
            <div>
                <table class="table-no-borders">
                    <tr>
                        <td>
                            @Html.LabelFor(x => x.selCountry)
                        </td>
                        <td>
                            @Html.DropDownListFor(x => x.selCountry, Enumerable.Empty<SelectListItem>())
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.LabelFor(x => x.selServiceName)
                        </td>
                        <td>
                         @Html.TextBoxFor(x => x.selServiceName)
                        </td>
                    </tr>
                    <tr>
                       <td>@Html.LabelFor(x => x.isAudit)</td>
                        <td>
                            @Html.RadioButtonFor(x => x.isAudit, true, new { @id = "radAudit" }) 
                            <label for="radioAudit">Audit</label>
                            &nbsp; &nbsp;
                       
                            @Html.RadioButtonFor(x => x.isAudit, false, new { @id = "radException" }) 
                            <label for="radioException">Exception</label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.LabelFor(x => x.selStartDateTime)
                        </td>
                    
                        <td>                        
                            @Html.EditorFor(x => Model, "propStartFullDateTime")
                        </td>
                    </tr>
                    <tr>
                        <td>
                          @Html.LabelFor(FTE =>FTE.selEndDateTime)   
                        </td>
                        <td>
                       
                          @Html.EditorFor(x => Model, "propEndFullDateTime")
                        </td>
                    </tr>
                    <tr>
                        <td>
                           @Html.LabelFor(x => x.selResultsPerPage)
                        </td>
                        <td>
                            @Html.DropDownListFor(x => x.selResultsPerPage, Model.commonProp.resultsPerPage)
                        </td>
                    </tr>
                </table>
                <input type="button" id="search_Transfer_Log_result" value="Submit" />
            </div>
        </fieldset>
     </form>

0
Khan Abrar Ahmed

Khan Abrar Ahmed

NA 5.8k 199.7k 10y

Create a model to pass into the view with the property on it:

public int ClickCount{get;set;}

Then in the view, create a hidden value

@Html.HiddenFor(f=>f.ClickCount)

During the post event on the controller, update the model

public ActionResult(ViewModel model){ model.ClickCount++; }
0
Anupam Singh

Anupam Singh

NA 5.8k 886.7k 10y
Hi srujana,

Share your code(View and Controller).