在Asp.net中搜索MVC区分大小写

时间:2017-04-26 10:19:15

标签: jquery ajax asp.net-mvc

我在Asp.net MVC项目中实现了一个搜索框。问题是这个函数区分大小写,我希望它不区分大小写。

我需要以某种方式更改它以禁用区分大小写。

这是我的jQuery代码:

$('#FormSearch').submit(function (event) {
event.preventDefault();

    var formsearch = $('#FormSearch');
    var serializedForm = formsearch.serialize();
    var searchString = $('#search').val();
    var input = $('#search').val();
    if (searchString == '' || searchString == undefined || searchString == 0) {
        searchString = "";
    }
    else {
        searchString = 'search=' + searchString;
    }
    var url = '/Home/Help?' + searchString;
    var replacement = '<span class="highlight">' + searchString + '</span>'; // define replacement text

    $(".ajaxloader1").show();

    $.ajax({
        url: url,
        type: 'POST',
        cache: false,
        data: serializedForm,
        success: function (result) {       
            window.history.replaceState("#intagsname", "Title", url);
            $('#intagsname').html(result);
            var x = $('#hs li').length;
            for (var i = 1; i <= x; i++)
            {
                var text = $("#hs li:nth-child(" + i + ") h5").html();
                text = text.replace(input, '<span class="test">' + input + '</span>');
                $("#hs li:nth-child(" + i + ") h5").html(text);
                var textans = $("#hs li:nth-child(" + i + ") p").html();
                textans = textans.replace(input, '<span>' + input + '</span>');
                $("#hs li:nth-child(" + i + ") p").html(textans);
            }
        }
    });    
});

这是我的控制器

    public ActionResult Help(string searchString)
    {
        searchString = Request["search"];
        var repsearch = new RepositorySearch();
        List<Question> question = new List<Question>();
        if (!string.IsNullOrEmpty(searchString))
        {
            question = repsearch.GetAllQuestion().Where(n => n.Qu.Contains(searchString)).ToList();
        }
        return Request.IsAjaxRequest() ? (ActionResult)PartialView("_QuestionPartial", question) : View(question);
    }

这是我的QuestionPartial

@using iranhoidaytour_com.Models
@if (Model.Count > 0)
{
 <ul id="hs">
    @foreach (Question q in Model)
    {
        <li class="">
            <h5 class="quos">@q.Qu</h5>
            <p class="answ">@q.Ans</p>
        </li>
    }
   </ul>
 }

0 个答案:

没有答案