i work in simple demo to make asearch in asp.net mvc everything work normal except that the url including + character that prevent the function to be worked
the url looks like this http://localhost:3189/products/Index?term=+a&name=Search
when i edit it manually ,it works fine http://localhost:3189/products/Index?term=a&name=Search
this is my model
public class product
{
public int id { get; set; }
public string productName { get; set; }
public string productModel { get; set; }
public int productPrice { get; set; }
public int ModelNum { get; set; }
}
and i just used scaffolding to generate controller with views
after that this is my edits on controller
public ActionResult Index(string term)
{
List<product> products = (from pr in db.products
where pr.productName.Contains(term) || pr.productName == null
select pr).ToList();
if (products.Count <= 0 || products == null)
{
//select all
return View(db.products);
}
//result of search
return View(products);
}
this is my view code in index view
<form>
<input type="search" name="term" value=" " id="term" placeholder="enter your products"/>
<input type="submit" name="name" value="Search" />
</form>
and i really didn't know why this behaviours happens and from where the + signs added as when i remove it manually everthing work noramally the url looks like this http://localhost:3189/products/Index?term=+a&name=Search
when i edit it manually ,it works fine http://localhost:3189/products/Index?term=a&name=Search
this is not adublicte i pass only one value to url and the another question for passing multible values