Recovers data with Request.Querystring

Asked

Viewed 95 times

3

I have a Partial that loads the data:

@using (Html.BeginForm("PesquisarEventoPorLocal", "CadastroEvento", FormMethod.Get))
{
    <div class="row">
        <div class="col-sm-12 col-md-12">
            <div class="form-group col-md-3">
                <label for="sel2">Pesquisar Por local:</label>
                @Html.DropDownList("Pesquisa:", ViewBag.TiposLocal as SelectList, new { @class = "form-control", id = "comboBox", name= "comboBox" })
            </div>
            <div class="form-group  col-sm-3 col-md-3">
                <br/>
                <button type="submit" class="btn btn-danger">Pesquisar</button>
            </div>
        </div>
    </div>


}

No controller is passing data.

        [HttpGet]
        public ActionResult PesquisarEventoPorLocal()
        {
            string CodigoLocal = Request.QueryString["PesquisarEventoPorLocal"];
            string CodigoLocal1 = Request.QueryString["Pesquisa"];
            string CodigoLocal2 = Request.QueryString["comboBox"];

            return RedirectToAction("index", "CadastroEvento");
        }

2 answers

1


There are some errors in your code.

These low fields do not exist in your form, for them to exist you must create an input or select and add the attribute name and set a name for the element.

Searchtoporlocal

Research

combobox

Note: The code below does not work the way you are expecting

@Html.DropDownList("Pesquisa:", ViewBag.TiposLocal as SelectList, new { @class = "form-control", id = "comboBox", name= "comboBox" })

Mainly these two attributes:

id = "comboBox", name= "comboBox"

When you create a @Html.DropDownList the first paramêtro is the id and the name element, I still haven’t seen how you force the element to exchange the id and the name passed this data by the parameter htmlAttribute. That’s why when you give the Submit in the form you cannot catch the query Request.QueryString["comboBox"];


string CodigoLocal2 = Request.QueryString["comboBox"];

This code will be correct if you do so:

<div class="form-group col-md-3">
    <label for="sel2">Pesquisar Por local:</label>
    @Html.DropDownList("comboBox", ViewBag.TiposLocal as SelectList,"Pesquisa:", new { @class = "form-control" })
</div>
  • I appreciate the help

1

In his BeginForm you say you must submit the data to CadastroEvento.

But in your controller, you expect the data in PesquisarEventoPorLocal.

suggested improvement

[HttpGet]
public ActionResult PesquisarEventoPorLocal(string pesquisarEventoPorLocal, string pesquisa, string comboBox) {...}
  • searchEventoPorLocal and a Partial, which loads the data, then I am sending to the Registersevent because the research and held there, I will test your idea, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.