mercredi 19 août 2015

Filtering 2 textboxes in mvc4?

I Have 2 text boxes

1)text box as resource

2)text box as location

For the #1 text box am getting resource records from database based on search criteria. my problem is that

When i enter keyword in #1 text box and at the same time when i enter location in #2 text box i need to fetch the result by filtering result based on location.

How do i fit location filter on it ??

MY view

<div class="searchform cf">
    @using (Html.BeginForm())
    {
        <input type="text" name="txtValue" id="txtValue" value="@Session["searched"]" placeholder="What ?">
    <input type="text" name="txtLocation" id="txtLocation" placeholder=" City or State">
    <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)
                    {                       
                        <div class="tiptext">
                            <b style="margin-left: -8px; font-size: large;color: #1A0DB2;">@item.FirstName</b>
                            <h3 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);"> @item.BusinessName</h3>
                            <h3 style="margin: 0px; color:black">@item.BusinessCategory </h3>
                            <h3 style="margin: 5px 0px 5px 0px;color: rgb(0, 145, 0);"> @item.BusinessDescription</h3>
                            <div class="description">
                                <div id="map" style="width:400px; height:200px"></div>
                                <b>Address1 :</b><h4 class="des">@item.Address1</h4>
                                <b>Address2 :</b><h4 class="des">@item.Address2</h4>
                                <b>Email :</b><h4 style="color:blue; margin: 5px 0px 5px 0px;">@item.EmailID </h4>
                                <b>WorkNumber :</b><h4 class="des">@item.WorkNumber</h4>
                                <b>MobileNumber :</b><h4 class="des">@item.MobileNumber</h4>
                                <b>City :</b><h4 class="des">@item.City</h4>
                                <b>State :</b><h4 class="des">@item.State</h4>
                                <b>ZipCode :</b><h4 class="des">@item.ZipCode</h4>
                            </div>
                        </div>
                    }
                </div>
            }
            else
            {
                <label id="lblErrorMsg" title="Record not fount...!" style="color:red;">Record not found...!</label>
            }
        }
    }
</div>

Controller:

 public ActionResult Index(string txtValue, string txtLocation)
    {
        var s = txtValue.ToString();
        Session["searched"] = s;
        if (txtValue.Length > 0)
        {
            string[] keywords = txtValue.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            var parameter = new SqlParameter[1];
            parameter[0] = new SqlParameter { ParameterName = "keyword", Value = txtValue };
            List<Search> cm = new List<Search>();
            using (SYTEntities context = new SYTEntities())
            {
                cm = context.Database.SqlQuery<Search>("exec Sp_Search @keyword", parameter).ToList();

            }

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

Model

public class Search {

public int BusinessID { get; set; }

public string BusinessName { get; set; }

public string BusinessCategory { get; set; }
public string BusinessDescription { get; set; }

public int UserID { get; set; }
public string FirstName { get; set; }
public string EmailID { get; set; }

public string MobileNumber { get; set; }
public string WorkNumber { get; set; }
public int AddressID { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }

public string City { get; set; }

public string State { get; set; }

public string ZipCode { get; set; }
public string StartTime { get; set; }

public string EndTime { get; set; }

}

Aucun commentaire:

Enregistrer un commentaire