Sunday, 25 August 2013

applying searching in asp.net mvc4

applying searching in asp.net mvc4

I am newbie to asp.net MVC4. For searching names from list i tried a
search filter in MVC4.
This is controller-
public ActionResult SearchUser(string Email, int? UserId) {
var system = from u in db.SystemUsers
select u;
if (!String.IsNullOrEmpty(Email)) {
system = system.Where(c => c.Email.Contains(Email));
}
return View(system.Where(x=>x.Email==Email));
}
View-
<input type="text" id="search-User" />
<button id="text-email">search</button>
Ajax handling-
<script type="text/javascript">
$(document).ready(function () {
$('#text-email').click(function () {
var areavalue = $('#search-User').val();
alert(areavalue);
$.ajax({
url: '/Allusers/SearchUser/?Email=' + areavalue,
type: 'get',
datatype: 'json'
});
});
});
</script>
I have many users as a list, so i wanted to filter out any user from the
list. For this I am using input element to get exact name as it is in
list. Thus this name is passed to controller to find the exact match.
It is showing value i passed through ajax handling but not showing
filtered result.
How can I perform searching in Asp.net MVC4?

No comments:

Post a Comment