简体   繁体   English

从另一个视图搜索时被重定向

[英]getting redirected when searching from another view

ok, so i have a project (Asp net core) that i am working on and i have created the controller and the model and i have implemented a searching mechanism here好的,所以我有一个正在处理的项目(Asp net core),我已经创建了 controller 和 model 并且我在这里实现了搜索机制

public async Task<IActionResult> Index(string searchString)
        {
            var drugs = from m in _context.Drugs
                select m;

            if (!String.IsNullOrEmpty(searchString))
            {
                drugs = drugs.Where(s => s.Name.Contains(searchString));
            }



            return View(await drugs.ToListAsync());
        }

and it works very well so the issue is i can't search from my home page whenever i add the search string and hit the button it redirects me to the drugs index i don't want that i have implemented a bootstrap modal and i want my results to be displayed there.so how can i search my model from another view without getting redirected please i need your help.它工作得很好所以问题是每当我添加搜索字符串并点击按钮时我都无法从我的主页搜索它会将我重定向到药物索引我不希望我已经实现了引导模式并且我想要我的结果将显示在那里。所以我如何从另一个视图搜索我的 model 而不会被重定向,我需要你的帮助。 Thanks a million太感谢了

Presumably you are just using a standard HTML form to submit the "search".大概您只是使用标准的 HTML 表单来提交“搜索”。 It's not "redirecting" you;这不是“重定向”你; you are literally telling the browser to request a new URL and display that in the browser tab/window.您实际上是在告诉浏览器请求新的 URL 并将其显示在浏览器选项卡/窗口中。 If you want to remain on the same page, then you must use AJAX to make the request.如果您想保持在同一页面上,则必须使用 AJAX 发出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 搜索 - 从索引视图和结果到另一个视图 - Searching - from index view and result to another view 从局部视图重定向时在MVC中调用Action - Calling an Action in MVC when redirected from a partial view 重定向到页面时,不会调用page_load - page_load not getting called when redirected to it 从原始 URL 获取重定向的 URL - Getting the Redirected URL from the Original URL 从另一个局部视图调用MVC局部视图 - MVC partial view getting called from another partial view 从带有帖子的视图中发送值,然后在另一个视图中获取它们 - Send values from a view with a post and getting them in another view 获取值以在同一视图中从一种形式持久化到另一种形式 - Getting a value to persist from one form to another in the same view 使用另一个类的bool方法搜索列表框。 获得“并非所有代码路径都返回值”。 知道为什么吗? - Searching a listbox using a bool method from another class. Getting 'not all code paths return a value'. Any idea why? 如何在不重定向的情况下在数据库中创建新行的同时重新加载部分视图 - How to reload a Partial View while also creating new Row in DB without getting redirected 从重定向页面退回时如何更新网页? - How to update webpage when you back from the redirected page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM