MVC搜索具有2种可能的视图结果. [英] MVC Searching with 2 possible view outcomes.

查看:623
本文介绍了MVC搜索具有2种可能的视图结果.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是MVC 3的新手,我已经适应了需要做些事情并且不确定最佳路径的情况.我们在具有父子关系的数据库中有一组相关的主题.


概括地说:-

1)用户在每个页面的搜索框中输入一个字符串,然后单击提交.
2)Ajax发布到搜索控制器,该控制器检查具有2种可能结果的搜索结果


2.1)如果我们有多个(父)飞蛾.系统会向用户显示前十个父项匹配项,从而导致用户选择一个(单击链接),然后选择完全匹配项,因此转到2.2


2.2)我们有一个完全匹配的内容-搜索与此父级相关的主题,并由DB进行排队和缓存,加载视图,结果准备好后由ajax异步返回.

Hi Guys,


I''m fairly new to MVC 3 and i''ve come accorss a situation where i need to do something and i''m not sure of the best path. we have a set of topics related in a database with a parent-child relationship.


in a nutshell : -

1) user enters a string into search box, which is on every page, and clicks submit.
2) Ajax post to search controller which checks the reults of the search with 2 possible outcomes


2.1)IF we have more than one (parent) macth. the top ten parent matches are shown to the user, which results in the user choosing one (clicking a link) and and exact match so move on to 2.2


2.2) We have one exact match - a search for topics relating to this parent are queued and cached by the DB, we load the view and the results are returned Asynchronously by ajax when they are ready.

推荐答案

我不会给您解决方案,而只是向您显示路径.

1.通过了解您的场景,我建议您使用实体框架,这样很容易通过父子关系向数据库提出请求.

2.您可以在视图页面上动态生成链接,并使用JavaScript函数将这些链接附加到其中,并将适当的id(从数据库[parentids]动态获取)作为参数传递到其中.

3.进入基于父ID的javascript函数,您可以异步请求下一个搜索结果,并使用ajax(jquery)更新页面.

4.还建议使用JQuery,它使您的ajax请求和动态页面更新过程变得简单.
I will not give you solution but just showing you the path.

1. By understanding your scenario I will suggest you to use entity framework so it is easy to make request to database by parent child relationship.

2. You can generate links on the view page dynamically and attach those links with javascript function into which appropriate ids(dynamically fetched from database [parentids]) is passed as a parameter.

3. Into javascript function based on the parent id you can asynchronously request for next search result and update your page using ajax(jquery).

4. Also suggest to use JQuery which made your ajax request and dynamically page updation process simple.


这篇关于MVC搜索具有2种可能的视图结果.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆