asp.net-mvc - 子域内的 ASP.NET MVC 应用程序中的表单数据始终为空
问题描述
我有两个 Asp.Net MVC 网站。第一个在根域domain.com内,第二个是子域sub.domain.com。
在根域内一切正常,但我无法将表单提交到子域上的控制器。无论我试图发送什么似乎永远不会到达控制器。
这可能看起来很奇怪,但是当我尝试以调试模式在本地启动应用程序时不会发生此问题。(本地不是子域,只是普通的本地主机)。
仅出于测试目的,我建立了一个简单的模型:
public class TestModel
{
public string test_text { get; set; }
}
这是 CSHTML 部分视图:
@using (Html.BeginForm("TryModel", "Home", new { }, FormMethod.Post, new { }))
{
<input type="text" name="test_text" />
<button type="submit">Test</button>
}
即使使用这个简单的配置,在我的本地副本上我也没有问题,但是一旦我在远程机器上启动应用程序,发布的数据总是空的。
你认为可能是什么问题?
编辑
这是控制器方法
[HttpGet]
public ActionResult TryModel()
{
return View();
}
[HttpPost]
public ActionResult TryModel(TestModel model)
{
// code removed
return View(model);
}
是的,该动作被正确调用。甚至 Request.Form 也是空的。
解决方案
Html.BeginForm 只需要 4 个参数,
参数:字符串 actionName、字符串 controllerName、FormMethod 方法、对象 htmlAttributes
你应该改变你的参数:
@using (Html.BeginForm("TryModel", "Home", new { }, FormMethod.Post, new { }))
至:
@using (Html.BeginForm("TryModel", "Home", FormMethod.Post, new { }))
我希望它会有所帮助。
推荐阅读
- php - Cannot declare class Error, because the name is already in use
- c# - SelectToPdf html to pdf conversion makes the font size slightly smaller. There is a way to configure font size from settings?
- python - Is there a known issue with memory leaks in Python dicts or Numpy iterators?
- r - EpiDisplay ordinal.or.display p 值的结果与 MASS 包中 polr 的计算 p 值存在差异?
- scala - IntelliJ 中 Scala 2.13.0 的 Gatling 兼容性问题
- apache-kafka - 如何使用 kafka-configs 查看和设置 offsets.retention.minutes
- sql - 在 SQL 中显示三个不同表中的三个不同列
- kotlin - 在 Kotlin 脚本中使用绑定 (Jsr 223)
- openssl - 尝试通过 CFSSL (multirootca) 使用经过身份验证的远程签名
- javascript - 如何从html页面解析json中的图像