regex - How to Filter special characters or anything that doesn't matches the search String in MVC -


I want to enter the search string in a way that it does not accept anything except the matched string for the search Does.

Here is my controller code:

Public Functional Search Product (String Searchstrassing) {FlipkartDbCTXTTAT DB = New FlipkartDBCCTs (); If (ModelState.IsValid) {// if ModelStat true string noResult = "search result not found"; Var Products = P in DB Select product p; If (! String.IsNullOrEmpty (search-string). Trim ())) {products = products.Where (s = & gt; s.ProductName.Contains (SearchString)); See Return (products.ToList ()); } And {ViewBag.Message = noResult; See refund (new list & lt; product & gt; ()); }} Other {ModelState.AddModelError ("", "Search is not successful"); } See Return (); } "Search result not found" is being displayed for blank entry only..but I want to display it for any other characters that do not match the search string. .

How do I do this?

Try it out:

  if (ModelState.IsValid) {/ / If ModelStat is not the correct string = result = "search result not found"; // Ternary Express to return a new list if the search string is empty or empty var products = string. ISNLLL (RTL) (SRT))? New list & lt; Products & gt; (): Db.Products. Where (s = & gt; s.ProductName.Contains (SearchString)); // Set viewbag message if the list is empty, (! Products.Any ()) {ViewBag.Message = noResult; } See Return (products.ToList ()); } Other {ModelState.AddModelError ("", "Search is not successful"); }  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -