Technical Articles

Search box in MVC

0 0
Put in Index File…
<p>
   @using (Html.BeginForm(“Index”, “Department”, FormMethod.Get)) {
   <b>Search By:</b>@Html.RadioButton(“searchBy”, “search”,true)<text>Name</text>
       @Html.TextBox(“search”)<input type=”submit” value=”search” />
   }
    </p>

—DepartmentController
 public ActionResult Index(string searchBy, string search)
        {
            if (searchBy == “Name”)
            {
                return View(db.Departments.Where(x => x.DprtName.StartsWith(search)).ToList());
            }
            else
            {
                return View(db.Departments.Where(x => x.DprtName.StartsWith(search)).ToList());
            }
         
        }

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
× How can I help you?