【发布时间】:2013-02-08 05:38:39
【问题描述】:
我的 jQuery mobile \ MVC 应用程序有一个有点奇怪的问题,到目前为止我无法找到。
在我看来,我有 2 个 HTML.HiddenFor 字段。当表单发布时,这些字段中的值绑定到我的控制器中的模型类的属性。属性是 Double 类型。 在我的本地开发机器上发布表单时,值绑定正常。但是,当我的应用程序部署到远程服务器时,模型绑定停止工作,使其再次工作的唯一方法是将属性类型从 Double 更改为 string。
这是我的模型:-
public class HomeViewModel
{
public Double Latitude { get; set; } //form value binds locally but does not bind on remote server
public Double Longitude { get; set; } //form value binds locally but does not bind on remote server
public string LatitudeStr { get; set; } //form value binds
public string LongitudeStr { get; set; } //form value binds
这是我的看法:-
@using (Html.BeginForm("Index","Branches", FormMethod.Post, new { ID = "frmSearch", data_transition = "none" })){
@Html.HiddenFor(model => model.Latitude, new { id = "hdnLat" })
@Html.HiddenFor(model => model.Longitude, new { id = "hdnLong" })
这是我的控制器:-
[HttpPost]
public ActionResult Index(HomeViewModel model)
{
当我在提交表单后检查页面时,我可以看到 input-validation-error 类已附加到隐藏元素:
查看 Firebug 中的发布信息,我可以看到已发布值。
以上在本地运行良好,但不能从远程服务器运行。
据我所知,在本地和远程运行时,完全相同的值会回传到服务器
如果有人能对此有所了解,那就太好了
【问题讨论】:
-
哪个部分不工作?你能在你的索引中打断点吗?你得到 404 了吗?
-
不起作用的部分是控制器中字段值与模型的绑定。我可以在萤火虫中看到已发布值,但在控制器中 model.Latitude 和 model.longitude 值为空。这只发生在远程运行应用程序时,它工作正常并且值在本地绑定良好
-
当你说远程服务器 - 你正在使用同一个客户端发布但应用程序不再在同一个盒子上运行?
-
是的,我使用的是同一个客户端,但应用程序部署到本地网络之外的 Web 服务器
标签: c# asp.net-mvc jquery-mobile asp.net-mvc-4