如何在asp.net mvc 5中的弹出模式中实现搜索功能

时间:2021-03-15 14:30:20

Here is my problem, I want to create a pop up modal which contain text input field and button and drop down list to select which column. And when I search , it should show the result in a table or grid in the same modal with links to select each record.

这是我的问题,我想创建一个弹出模式,其中包含文本输入字段和按钮和下拉列表以选择哪一列。当我搜索时,它应该在同一模态中的表格或网格中显示结果,并带有选择每条记录的链接。

I'm new to the asp.net mvc and I don't have much background. I only want to know that how should I do this? what should I use(eg. jsonResult, ajax etc.) to implement this? Can someone explain me the steps? I know it's lot to ask. Can someone please help me? I've created a partial view with html beginform to pass the string Query form view to controller and here it is,

我是asp.net mvc的新手,我的背景不多。我只想知道我应该怎么做?我应该使用什么(例如,jsonResult,ajax等)来实现这个目的?有人可以解释一下这些步骤吗?我知道要问很多。有人可以帮帮我吗?我用html beginform创建了一个局部视图,将字符串查询表单视图传递给控制器​​,在这里,

    @model SmartPhotographer.Models.Client
    <!DOCTYPE html>
    <html>
    <head>
      <meta name="viewport" content="width=device-width" />
      <title>Index</title>
   </head>
   <body>
    @using (Html.BeginForm("Search", "Reservation", FormMethod.Post))
     {
       <table cellpadding="0" cellspacing="0">
          <tr>
            <th colspan="2" align="center">Person Details</th>
          </tr>
           <tr>
            <td>Search text: </td>
            <td>
                @Html.TextBoxFor(m => m.FirstName)
            </td>
            <tr>
            <td></td>
            <td><input type="submit" value="Submit" /></td>
          </tr>
       </table>
     }    
    </body>
   </html>

and my action result for that partial view,

和我对该局部视图的行动结果,

    [HttpPost]
    public ActionResult Search(Client ClientDtl)
    {
        string FirstName = ClientDtl.FirstName;
        Session["search"] = FirstName;
        return PartialView();
    }

and I've passed the session variable to another action to find the record,

我已将会话变量传递给另一个动作来查找记录,

    public ActionResult Search()
     {
        string SearchText = Session["search"].ToString();
        var Search = from m in db.Client
                     select m;
        Search = Search.Where(s => s.FirstName.Contains(SearchText));
        return PartialView("Search",Search);
    }

and i want this searched results to show in same partial view.

我希望这个搜索结果显示在相同的局部视图中。

1 个解决方案

#1


0  

Look at the Ajax Toolkit that will let you create a modal popup. You can then implement your desired functionality in the modal.

查看将允许您创建模态弹出窗口的Ajax工具包。然后,您可以在模式中实现所需的功能。

The modal will be just like a panel, you can place the controls you want inside the modal and preform your search etc.

模态就像一个面板,你可以将你想要的控件放在模态中并预先形成你的搜索等。

#1


0  

Look at the Ajax Toolkit that will let you create a modal popup. You can then implement your desired functionality in the modal.

查看将允许您创建模态弹出窗口的Ajax工具包。然后,您可以在模式中实现所需的功能。

The modal will be just like a panel, you can place the controls you want inside the modal and preform your search etc.

模态就像一个面板,你可以将你想要的控件放在模态中并预先形成你的搜索等。