简体   繁体   English

有没有办法将表单的提交按钮放在另一个视图中?

[英]Is there a way place submit button of a form inside another view?

My problem is as following: I have a controller called "SettingController" contains a view called SSO.cshtml, and there is a form in it.我的问题如下:我有一个名为“SettingController”的 controller 包含一个名为 SSO.cshtml 的视图,其中有一个表单。 I also have a controller called "UserController" contains view "Index.cshtml".我还有一个名为“UserController”的 controller 包含视图“Index.cshtml”。 Index view has button "Submit".索引视图有“提交”按钮。 In UserController there is a HttpPost method call SyncSSO() return ActionResult.在 UserController 中有一个 HttpPost 方法调用 SyncSSO() 返回 ActionResult。 I want to make button "Submit" become submit button of form in SSO.cshtml and after clicking it, an instance of model contains information of fields of this form will be sent to SyncSSO().我想让按钮“提交”成为 SSO.cshtml 中表单的提交按钮,单击它后,包含此表单字段信息的 model 实例将被发送到 SyncSSO()。 Is there a way like that?有没有这样的方法?

If you are trying to use ButtonType as Submit then it will Post all the data on the Page.如果您尝试使用 ButtonType 作为提交,那么它将在页面上发布所有数据。 and If you just want to POST few fields or only selected data then Go with AJAX call, which is better option.如果您只想发布几个字段或仅发布选定的数据,那么 Go 与 AJAX 调用,这是更好的选择。

Below is the example I have copy pasted:以下是我复制粘贴的示例:

$.ajax({
    type: "POST",
    url: '@Url.Action("FirstAjax", "AjaxTest")',
    contentType: "application/json; charset=utf-8",
    data: { a: "testing" },
    dataType: "json",
    success: function() { alert('Success'); },
    error: errorFunc
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM