我使用的是 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&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:型号缺少局部视图数据
发布评论