views:

55

answers:

2

i have a textbox with button search. i would like to search my database of input text from textbox and give result out in one view. Could you please give me link or help me how its possible to implement? I have no idea what i shoul to do that.

A: 

Hello,

Check out the tutorials on asp.net, they are pretty good and will get you started with ASP.NET MVC: http://www.asp.net/mvc

HTH.

Brian
yeah, but its any lesson/video/tutorial about my problem over there.
Ragims
"problem"? you have a View, which has a field and button. On button click, you go to a controller, get some stuff, then show a view. I think this is pretty common - hence @Brian pointing you to the ASP.NET MVC Tutorials.
RPM1984
A: 

If you want to show the result in the same view page as that of the search criteria text box, the better approach will be to go with JQuery form post. And from the corresponding controller you can get back the JSON result and bind it to the grid, if you are using any third party grid.

The posting mechanism will be :

      <div>
            <input type="text" id="txtSearchText" value=""/>
            <input type="button" id="btnSearch" value="Search"/>
      </div>
            <script type="text/javascript">
               $("#btnSearch").click(function(){
                  var formPost={ SearchText : $("#txtSearchText").val()}; 
//The above SearchText parameter name should be same as property name in the Model class.
                  $.post("/SearchController/Search",formPost,function(data){
                  if(data)
                  {
                     //Here based on your development methodology, either build a table by    
                      //appending a row for each result Or bind to a grid, if you are using  
                      //any third party control
                  }
                  });
               });

            </script>
Controller Code :
public class SearchController
{
    public ActionMethod Search(SearchModel searchCriteria)
    {
           SearchResultModel result= //Get the search results from database
           return new JsonResult{Data=result};
    }
}

Model class:
public class SearchModel
{
public string SearchText{get;set;};
}
Siva Gopal