0

net mvc 5 and have a view "Search.cshtml" and a controller "HomeController" and a model "user".

I try to create a DataTable out of Active Directory and show this in a table in the view.

I can show the table in the view but i want to implement a search textfield for selection a value in this table.

For this I create a method for testing and have the Method in my controller:

public ActionResult Search(string searchString){
    var data = GetTable(searchstring);
    return View(data);
}

static DataTable GetTable(string data){
   //...here i get data from the active Directory and filter with data parameter
}

And here is my View

<h2>Suchen</h2>

@using(HTML.BeginForm()){

   @Html.TextBox("SearchString") 

   <input type="submit" value="Suchen">

   <table>
     <thead>
       <tr>
         @foreach(DataColumn col in MOdel.Columns){
                     <th>@col.ColumnName</th>
         }
       </tr>
     </thead>
     <tbody>
      @foreach(DataRow col in Model.Rows){
         <tr>
           @foreach(DataColumn col in Model.Columns){
            <td>@row[col.columnName]</td>
           }
         </tr>
       }
     </tbody>
   </table>

}

How I can post my SearchString to my Controller and then I know wht i must do ;)

1
  • 1
    Try using the exact same name for the textbox as in the controller searchString (LowerCase s) Commented Oct 9, 2015 at 10:41

1 Answer 1

1

Just specify action and controller name in the BeginForm method:

@using(Html.BeginForm("Search", "Home")){

Also I believe parameter names are case sensitive, so make sure textbox name corresponds to that of action parameter:

@Html.TextBox("searchString")

Assuming you do not have any special routing setup, that should do it - when user clicks submit button, "Search" action should get triggered.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.