尝试从另一个应用程序使用返回类型视图调用控制器操作方法时发生CORS错误

时间:2019-04-29 06:31:35

标签: asp.net-mvc model-view-controller cors http-post actionresult

正在尝试触发application-1的Post方法并在新窗口或新标签页中打开。

Application-1

public class TestController : Controller
{
    [HttpPost]
    public ActionResult PostSearch(object searchInput)
    {
      return RedirectToAction("Index", "Studnet")
    }
}

想要从application-2触发此post方法。

<input type="button" id="search"  
value="Trigger Post"  onclick="TriggerPostSearch('1234')"/> 

 function TriggerPostSearch(searchObject) {
        var url = "http://www.localhost:99/test/PostSearch";
        OpenWindowWithPost(url, searchObject);
    };

  function OpenWindowWithPost(url, model) {
        var param = { "searchInput": model };
        $.ajax({
            url: url,
            type: "POST",
            contentType: "application/json",
            data:param
        }).done(function(result){
        window.open(url, '_blank');
        });
    }

在app-1中启用CORS以接受来自app-2的请求。还有其他方法吗?

0 个答案:

没有答案
相关问题