TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
osyris zosar
NA
289
26.7k
Return View with multiple parameter
Feb 28 2021 6:24 AM
I am trying to create a filter system in C# mvc where i can use multiple input fields for filtering:
View:
<form asp-controller=
"Products"
asp-action=
"Index"
>
<p>
Title: <input type=
"text"
name=
"SearchString"
/>
Description: <input type=
"text"
name=
"SearchString"
/>
<input type=
"submit"
value=
"Filter"
/>
</p>
</form>
Model:
public
class
Product
{
public
int
Id { get; set; }
public
string Title { get; set; }
public
int
Price { get; set; }
[Display(Name =
"Product description"
)]
public
string ProductDescription { get; set; }
public
int
Stock { get; set; }
}
Controller:
public
async Task<IActionResult> Index(string searchString, string description)
{
var store = from m in _context.Products
select m;
if
(!String.IsNullOrEmpty(searchString))
{
store = store.Where(s => s.Title.Contains(searchString));
}
if
(!String.IsNullOrEmpty(description))
{
store = store.Where(s => s.ProductDescription.Contains(description));
}
return
View(await store.ToListAsync());
}
I am not really sure how i can manage this the best possible way
Reply
Answers (
6
)
EF vs Dapper which is better
Linq samples for practise.