开发者

Populate text box based on search criteria in MVC C#

I am trying to populate a couple text bo开发者_JAVA百科x fields in my MVC application. I have a text box that a user can enter an ID and then click search, and based on the ID input from the user, information should be brought back to populate First Name, Last Name text boxes on the same page.

The problem I am having is bringing back this data from a SQL Stored Procedure and displaying the results on the same page in different text boxes. I just can't seem to figure out how to bring that information back to the same page instead of having to show a different view.

Any advice or solutions would be greatly appreciated.

Thanks.


You decide which View to show in the return from your Action; why do you feel forced to show a different one?


"how to bring that information back to the same page"

call the Action over the same controller.

For displaying data in Textboxes, fetched from DataSource, use

           <%= Html.TextBox(Model.FirstName)%>               
           <br />
           <%= Html.TextBox(Model.LastName)%>
           <br />
           <%= Html.TextBox(Model.SearchResults)%>

review these Tutorials

  • Creating Custom HTML Helpers
  • Displaying a Table of Database Data

Hope this helps


Question is really vague but at a guess, you want AJAX functionality, something like this....

$.post("/Home/Search",                      //action to post to
       { query: $('#searchBox').val() },    //data to post, ie. search box text
        function(data){                     //callback function to process return data  somehow.
            alert("Data Loaded: " + data);  //do what you want here
        }
 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜