MVC:型号缺少局部视图数据

编程入门 行业动态 更新时间:2024-10-21 14:46:00
本文介绍了MVC:型号缺少局部视图数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是 Telerik的 PanelBar做使用的局部视图一些异步加载。我创建了一个父视图的局部视图的模型,但由于某些原因,我的数据是不是在机智未来通过。

I'm using the Telerik PanelBar to do some asynchronous loading using a partial view. I'm creating a model for the partial view in a parent view, but for some reason my data isn't coming through in tact.

// Parent view <% Html.Telerik().PanelBar().Name("PanelBar").HtmlAttributes(new { style = "padding-left: 0em;" }).Items(items => { foreach (var item in Model.Visits) { SiteVisitDetailModel model = new SiteVisitDetailModel(); model.URL = item.Key; // this is properly set model.Dates = new List<DateTime>(); // this is null in the controller model.Dates.Add(DateTime.Now); items.Add() .Text(item.Key.ToString() + " " + item.Count().ToString() + " visits") .LoadContentFrom("SiteViewDetail", "Report", model); } }).Render(); // Report controller method public ActionResult SiteViewDetail(SiteVisitDetailModel model) { return PartialView(model); // model.URL is correct, model.Dates is null } // Model public class SiteVisitDetailModel { public String URL { get; set; } public List<DateTime> Dates { get; set; } }

正如我的意见,当控制器的SiteVisitDetail方法称为建议的,Model.URL具有正确的数据,以及Model.Dates为空(这不是包含空列表,它本身为空)。这,正如所预料的,也是在局部视图(SiteViewDetail)空。

As suggested by my comments, when the controller's SiteVisitDetail method is called, Model.URL has the correct data, and Model.Dates is null (it's not a list containing null, it itself is null). It, as would be expected, is also null in the partial view (SiteViewDetail).

什么会导致这种行为?

推荐答案

原来正在构建的查询字符串是不正确的。它的产生是这样的:

It turns out the query string being built isn't correct. It's generating something like:

?value1=somevalue&amp;value2=whatever

因此​​,尽管价值是存在的,正确的,它没有得到正确解析,因为放大器;

So while the value is there and correct, it's not getting parsed properly because of that amp;.

我猜这是与Telerik的控制问题。我会报告错误,看看他们怎么说。

I'm guessing this is a problem with the Telerik control. I'll report the bug and see what they say.

由于这似乎是这个问题,我只是将一切连接成一个大的字符串并解析它在控制器,直到一个更正式的办法可以解决。

Since that appears to be the problem, I'm just going to concatenate everything into one big string and parse it in the controller, until a more formal solution can be found.

感谢您的帮助,马亭。

更多推荐

MVC:型号缺少局部视图数据

本文发布于:2023-11-08 13:58:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   局部   型号   数据   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!