Click here to Skip to main content
16,019,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
mvc3 textbox retaining after button click.

my view code.


HTML
States Filter :

@Html.TextBox("Statestxt")
<input type="image" value="submit" src="../../Images/FilterBrowse.gif" alt="submit Button" />


My controller:

C#
public ActionResult AutocompleteAsync(string term)
{
    var suggestions = from s in Adm.states
    select s.state_name;
    var namelist = suggestions.Where(n => n.ToLower().StartsWith(term.ToLower()));
    return Json(namelist, JsonRequestBehavior.AllowGet);
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult States(state stateModel, string _stateName, FormCollection formvalues)
{
    AdmDataContext Adm  = new AdmDataContext;
    if (Request.Form["Statestxt"] == null)
    {
        ViewBag.Error = "Enter State Name.";
        ViewData["name"] = false;
        return View();
    }
    else
    {
         _stateName = Request.Form["Statestxt"].ToString();
         var record = (from state in Adm.states
                                  where state.state_name == _stateName
                                  select state).Count();

         if (record == 0)
         {
             ViewBag.Error = "Enter Valid State Name.";
             return View();
         }

         var _Stateid = from state in Adm.states
                                  where state.state_name == _stateName
                                  select state;

         int StateId = (int)_Stateid.First().state_id;
         var state1 = am.FindUpcomingStates2(StateId).ToList();
         if (state1 != null)
         {
               ViewData["name"] = true;
               return View("States", state1);
         }
     }
}


Here after clicking submit button textbox is going to empty. How can i write code for textbox should not be empty.

Thanks.
Posted
Updated 11-Apr-12 3:22am
v4
Comments
Ed Nutting 11-Apr-12 4:37am    
Edit: DRamatic formatting improvement - namely adding pre tags, removing numerous blank lines, proper code indentation, removal of a few odd tab space characters (replaced with spaces where necessary).
Ed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900