.NET核心HTML表单请求将页面重定向到相关查看页面,但使用JavaScript网站,它不会重定向到Action View Page
我想通过HTML表单和JavaScript提出呼叫控制的动作之间的区别。 如果我使用NetCore调用操作方法并将视图()OBJ返回到查看页面。
但是,当我调用相同的操作时,网页停留在同一页面中。
例如,您有一个员工列表页面,其中列出了所有员工,并希望在Emplpoyee详细信息页面中查看特定员工的详细信息。
使用HTML < form method ='post'action ='homployeedetails'> </form>
它可以正常运行,并且浏览器打开新页面。
但是使用javaScript
function postSelectedCustomerData(path, method = 'post') {
let data = {
SearchText: 'SearchText1',
EmpName: '1',
DealsOnly: true,
PageNumber: 1
}
fetch("../Employee/EmployeeDetailsPost", {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(res => {
console.log("Request complete! response:", res);
});
}
注意:我知道我可以从window.location.href fetch return重定向页面。但是我想知道有什么办法可以使用JavaScript调用Action方法并返回动作方法页面?
I would like to ask difference between calling Control's action via html FORM and JavaScript.
If I use NetCore calls the Action Method and returns View() obj into View page.
But when I call the same Action, webpage stays in the same page.
For example, you have a Employee List page where all employees are listed and wanted to see on of the specific employees details in Emplpoyee Details page.
With html<form method='post' action ='EmployeeDetails'> </form>
It works and browser opens the new page.
But with Javascript
function postSelectedCustomerData(path, method = 'post') {
let data = {
SearchText: 'SearchText1',
EmpName: '1',
DealsOnly: true,
PageNumber: 1
}
fetch("../Employee/EmployeeDetailsPost", {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(res => {
console.log("Request complete! response:", res);
});
}
NOTE: I know I can redirect the page from fetch Return with window.location.href. But I want to know is there any way i can call action method with JavaScript and return to the action Method page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用标准
&lt; form&gt;
框架功能时,服务器张贴回到客户端的HTTP响应,该响应由浏览器解释为要加载的新网页。当您使用简单的JavaScript
Fetch
跳过此功能时,处理响应都取决于您。从DOM的角度来看(假设您只会得到“ 200”响应!)您应该识别将要替换的现有树的父,删除所述树,将新的树插入响应中。When you use standard
<form>
framework functionality, the server posts back to the client an HTTP response that's being interpreted by the browser as a new web page to be loaded.When you skip this using a simple javascript
fetch
, the handling of the response it's all up to you. Just from a DOM point of view (let's suppose you only get '200' response!) you should identify the parent of the existing tree that will be replaced, remove said tree, insert the new one from the response.