Search code examples
asp.net-mvcasp.net-coreasp.net-mvc-4model-view-controllerasp.net-mvc-5

I am trying to use the search through sql proc and every time I get an error for not completing the code and I don’t know what to do


iam try to get data using sql proc and I try to execute the code, but every time the code is not created, and I don’t know the reason this is my classes

 public class CLS_ShowModels
    {
        public int ID { get; set; }
        public string Cid { get; set; }
        public string Sid { get; set; }
        public string ModelCode { get; set; }
        public string ModelName { get; set; }
        public string FloorID { get; set; }
        public string PathroomTypeID { get; set; }
        public string PathroomNameID { get; set; }
        public string Size { get; set; }
        public string DateShow { get; set; }
        public string Descreption { get; set; }
        public string StoreLocation { get; set; }
        public string ImageURL { get; set; }
        public string Image360URL { get; set; }

    }

this cmd class

 public CLS_ShowModels GetCategoryId(string name)
        {
            try
            {
                return cmd.GetSingle("SF_SearchPathroom @ModelName",
                    new
                    {
                        ModelName =name
                    });

            }
            catch (Exception)
            {
                return null;
            }
        }
        public List<CLS_ShowModels> GetAllShowRoom()
        {
            try
            {
                return cmd.GetAll("SF_SearchPathroom").ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

and this is the view code could you please help me in this task

 @using (@Html.BeginForm())
            {

                <table>
                    <tr>
                        <td>
                            <div class="input-group">
                                <input type="text" name="modelname" class="form-control" placeholder="Search...">
                                <span class="input-group-btn">
                                    <button type="submit" name="search" id="search-btn" class="btn btn-flat">
                                        <i class="fa fa-search"></i>
                                    </button>
                                </span>
                            </div>
                        </td>
                    </tr>
                </table>
            }
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.0.4/aframe.min.js"></script>

    @foreach (var item in Model)
    {

        <div class="col-md-3" style="margin-bottom:20px">
            <div class="thumbnail">
                <div class="img-responsive" style="margin-bottom:20px">
                    <img src="@Url.Content(item.ImageURL)" target="_blank" style="background-size:cover" height="240" width="240" />
                </div>
                <div class="caption" style="border-top:3px solid #808080">
                    @using (Html.BeginForm("Showpanorama", "PathroomShow", FormMethod.Post, new { target = "_blank" }))
                    {
                        <table cellpadding="2" cellspacing="0" border="0">
                            <tr>
                                <td></td>
                                <td>

                                    <h4 style="color:blueviolet;font:bolder"><input name="Name" hidden="hidden" type="text" value="@item.Image360URL" /></h4>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <input class="btn btn-info" type="submit" value="Panorama 360°" />
                                </td>
                            </tr>
                        </table>
                    }
                    @using (Html.BeginForm("ShowRoom", "PathroomShow", FormMethod.Post, new { target = "_blank" }))
                    {
                        <table cellpadding="2" cellspacing="0" border="0">
                            <tr>
                                <td></td>
                                <td>
                                    <h4 style="color:blueviolet;font:bolder"><input name="Name" hidden="hidden" type="text" value="@item.ImageURL" /></h4>
                                    <h4 style="color:blueviolet;font:bolder"><input name="Name1" hidden="hidden" type="text" value="@item.ModelName" /></h4>
                                    <h4 style="color:blueviolet;font:bolder"><input name="Name2" hidden="hidden" type="text" value="@item.Sid" /></h4>
                                    <h4 style="color:blueviolet;font:bolder"><input name="Name3" hidden="hidden" type="text" value="@item.Size" /></h4>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <input class="btn btn-info" type="submit" value="Show Room" />
                                </td>
                            </tr>
                        </table>
                    }
                    <h4 style="color:blueviolet;font:bolder"><a href="@Url.Content(item.ImageURL)" onclick="cataloge" target="_blank">@item.ModelName</a></h4>

                    <h5 style="color:darkslateblue;font:bolder"> Model : @item.Sid</h5>

                    <h5 style="color:blue;font:bolder">Size : @item.Size</h5>
                    <h5 style="color:red;font:bolder">Date : @item.DateShow</h5>

                </div>

            </div>
        </div>
    }

this is function controller

CLS_ShowModels Productdb = new CLS_ShowModels();
        cmdShowRoom showRppmcmd = new cmdShowRoom();
        public ActionResult Search(string search)
        {
            CLS_ShowModels Productdb = new CLS_ShowModels();
            cmdShowRoom showRppmcmd = new cmdShowRoom();


            return View((showRppmcmd.GetCategoryId.Where(x => x.ModelName.Contains(search) ).ToList());

        }

What is the error in the code showRppmcmd.GetCategoryId.Where


Solution

  • What is the code of showRppmcmd.GetCategoryId?If the method like this:

    public xxx GetCategoryId(){
    ....
    }
    

    You need to use showRppmcmd.GetCategoryId(). If the method like this:

    public xxx GetCategoryId(xxx xxxxx){
    ....
    }
    

    You need to use showRppmcmd.GetCategoryId(xxxxx).

    And you cannot use .ToList() in Where.You'd better to show GetCategoryId of cmdShowRoom.