如何在MVC4上执行类似的操作

如何在MVC4上执行类似的操作

本文介绍了如何在MVC4上执行类似的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Actual am fresher in I.T, This is my sql server query.. i need to implement on my project MVC ... can u explain or guide me how to do this in mvc ??


select * from tblBusinessCategory as b
inner join tblUser as u
on b.BusinessID=u.BusinessCategoryId
inner join tblAddress as a
on u.AddressId=a.AddressID
where u.BusinessCategoryId in
   (select BusinessCategoryId from tblBusinessCategory where BusinessCategory LIKE '%d%'
    UNION
    select BusinessCategoryId from tblBusinessCategory where BusinessName like '%d%'
    UNION
    select BusinessCategoryId from tblBusinessCategory where BusinessDescription like '%d%')



My controller

       public ActionResult Index(string txtValue)
        {
            var s = txtValue.ToString();
            Session["searched"] = s;
            if (txtValue.Length > 0)
            {
                string[] keywords = txtValue.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                return View(list);
            }
            else
            {
                ViewBag.Message = true;
                return View();
            }
        }

MY view:

<div class="searchform cf">
    @using (Html.BeginForm())
    {
        <input type="text" name="txtValue" id="txtValue" value="@Session["searched"]" placeholder="Need more ?">

        <button type="submit" value="Search" style="margin-top: 5px;">Search</button>
    }
</div>
<div style="margin: 35px 0px 0px 90px">

    @if (ViewBag.Message == true)
    {
        <label id="lblMessage" title="Please enter keyword" style="color:red;">Please enter keyword...!</label>
    }
    else
    {
        if (Model != null)
        {
            if (Model.Count() != 0)
            {

                <div>
                    <h2 style="font-size: 15px;">Searched for "<i style="  padding: 0px 10px; color: #595FFF;">@Session["searched"]</i>"</h2>
                </div>

                <div>
                    @foreach (var item in Model)
                    {

                        <b style="margin-left: -8px; font-size: large;color: #2B9CE2;">
                            @Ajax.ActionLink(@item.bName, "Businessdetails", "Search", new { id = item.bID }, null)
                        </b>
                        <div class="hover">
                            test
                        </div>
                        <h3 style="margin: 0px;">@item.bCategory</h3>
                        <h4 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);">@item.AddressID</h4>
                    <h4 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);">@item.UserID</h4>
                        <h4 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);">@item.MobileNumber</h4>
                        <h4 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);">@item.City</h4>
                    <h4 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);">@item.bDescription</h4>
                    }
                </div>
            }
            else
            {
                <label id="lblErrorMsg" title="Record not fount...!" style="color:red;">Record not found...!</label>
            }
        }
    }

推荐答案


这篇关于如何在MVC4上执行类似的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 01:54