lundi 10 août 2015

Drop down is not maintaining its State and showing only selected value

I want to select year from my drop down list and that year will be passed to my procedure in where clause and will get the results it works fine but on the view the selected value is only visible.

Example If I select 2015 from my drop down list which has 2015 and 2016 values then on the view only 2015 is visible on the drop down. Records are perfectly fetched.


 public class Data


    public string DataName { get; set; }

    public int Year { get; set; }


public ActionResult Test()
       VMNews objnews = new VMNews();
       if (Request["ddlYear"] != null)
            string selectedValue = Request["ddlYear"];
            objnews.DataName = db.Database.SqlQuery<Data>("usp_year @Year",new SqlParameter("@Year",selectedValue)).ToList();
        Response.Write("Nothing Selected");
        return View("Index",objnews);


 using (Html.BeginForm("Test","Home"))
    @Html.DropDownList("ddlYear", new SelectList(Model.MovieName, "Year", "Year"), "ALL")
    <button type="submit">Button</button>


Problem is there at the view level only, I had used the HTTPPost option on the controller and on the view ForMethod.POST but it didnt worked.

Aucun commentaire:

Enregistrer un commentaire