[英]Razor Pages on Asp.Net Core - Added Razor Page but cant get page to show
I am still figuring a lot out on Razor Pages for.Net Core and am a little stuck on something.我仍然在 Razor Pages for.Net Core 上找到很多东西,并且有点卡住了。 I have added a new Razor Page:我添加了一个新的 Razor 页面:
Which lives in the Pages
folder:位于Pages
文件夹中:
On an existing page I have added an Input and a button to initiate a Search:在现有页面上,我添加了一个输入和一个按钮来启动搜索:
Which onClick calls the following Javascript function:其中onClick调用如下Javascript function:
In the below screenshot, OnGetAsync method is hit when I put a breakpoint in, and can see the input value SearchValue is populated:在下面的屏幕截图中,当我在其中设置断点时会触发 OnGetAsync 方法,并且可以看到输入值 SearchValue 已填充:
However I would expect the browser to then display the Search.cshtml
page.但是,我希望浏览器随后显示Search.cshtml
页面。 Instead the browser just remains on the current index.cshtml page.相反,浏览器只保留在当前的 index.cshtml 页面上。
Am I missing something or am I just doing this incorrectly?我错过了什么还是我做错了?
However I would expect the browser to then display the Search.cshtml page.但是,我希望浏览器随后显示 Search.cshtml 页面。 Instead the browser just remains on the current index.cshtml page.相反,浏览器只保留在当前的 index.cshtml 页面上。
That is because $.get
will not call back the result only if you did something in success function.那是因为$.get
只有在您成功执行 function 时才会回调结果。
You need change jquery like below:您需要更改 jquery,如下所示:
@page
@model IndexModel
<input id="inpSearchMembers" placeholder="Search for a Member..." />
<input id="btnSearchMembers" type="button" value="Search" onclick="SearchMembers()" />
@section Scripts
{
<script>
function SearchMembers() {
var searchValue = $("#inpSearchMembers").val();
debugger;
$.get("/Search", { searchValue: searchValue }, function (data) {
window.location.href = "/Search"; //add this...
});
}
</script>
}
BTW, You create a button which is disabled
,it is impossible to click it and trigger the onclick event.顺便说一句,您创建了一个disabled
的按钮,无法单击它并触发 onclick 事件。
Actually,I think you could use form submit without using the jquery,change your Index.cshtml like below:实际上,我认为您可以在不使用 jquery 的情况下使用表单提交,将您的 Index.cshtml 更改如下:
@page
@model IndexModel
<form asp-page="Search" method="get">
<input name="searchValue" placeholder="Search for a Member..." />
<input type="submit" value="Search" />
</form>
In your page controller you should have an Action which returns the View:在您的页面 controller 中,您应该有一个返回视图的操作:
public IActionResult Search()
{
return View();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.