开发者

key=value asp.net mvc with url get?

a little problem for ya.

in master page i have a search input and link:

<input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" />
<%= Html.ActionLink("search", "Search", "Search", new{ searche = "txtSearche???what is here"}, null) %>

how can i write value in url "value" from input text and then get it in my search controller?

  [HttpGet]
        public ActionResult Search(string txtSearche)
        {
            try
            {
                SearchModel model = new SearchModel(txtSearche);
                if (txtSearche != null)
                {
                    return View(model);
                }
                else
                {
                    return View();
                }
            }

my biggest problem is here-> new{ searche = "txtSearche???what is here"} i dont know how to make开发者_如何学JAVA this part working


public ActionResult Search(string txtSearche, string searche) {

simple :) just put it in the parameters.

or you also can do string searche = Request["searche"] but in MVC, use the first option :)

Edit: ok i get what you want. you have an input form and you want to use this.

2 words: USE POST.

you are trying to make a get request in the URL what is actually a POST request. make a post, and then in your returning view, you can make the query come up in the URL as well.

the best thing is, make the postback, which will return navigate to the new URL with your searchquery in it with this

return RedirectToAction("Search", new { searche = txtSearche });


if you were hoping on getting the textbox input then you need to put it in a form with a submit button. Then you will capture "txtSearche":

<% using(Html.BeginForm()) { %>
  <input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" />
  <input type="submit" value="search" />
<% } %>

You will need to make your action accept [HttpPost] though. Unless you make your form use the GET method

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜