我正在尝试从模型更新模型。两个模型中的值都是整数。我知道如何传递文本字段,但我在传递整数时遇到问题。以下是我想要完成的事情。
因此,当我添加网页时,这将创建导航模型。
我正在尝试将此信息发送给模特。
LiColumn = MvcHtmlString.Create(webpage.NavColumn), **// needs to be integer**
LiColumnOrder = MvcHtmlString.Create(webpage.NavColumnOrder), **// needs to be integer**
这是GetModel代码:
public override object GetModel(Navigation widget)
{
var masterPages = GetPages(null);
var childPages = widget.IncludeChildren ? GetPages(masterPages) : new List<Webpage>();
var navigationRecords =
masterPages.Where(webpage => webpage.Published).OrderBy(webpage => webpage.DisplayOrder)
.Select(webpage => new NavigationRecord
{
LiText = MvcHtmlString.Create(webpage.Name),
LiUrl = MvcHtmlString.Create("/" + webpage.LiveUrlSegment),
LiColumn = MvcHtmlString.Create(webpage.NavColumn), **// needs to be integer**
LiColumnOrder = MvcHtmlString.Create(webpage.NavColumnOrder), **// needs to be integer**
Children = childPages.Where(webpage1 => webpage1.ParentId == webpage.Id)
.Select(webpage1 =>
new NavigationRecord
{
LiText = MvcHtmlString.Create(webpage1.Name),
LiUrl = MvcHtmlString.Create("/" + webpage1.LiveUrlSegment),
LiColumn = MvcHtmlString.Create(webpage.NavColumn), **// needs to be integer**
LiColumnOrder = MvcHtmlString.Create(webpage.NavColumnOrder) **// needs to be integer**
}).ToList()
}).ToList();
return new NavigationList(navigationRecords.ToList());
}
所以我的问题是如何使用MvcHtmlString
之外的其他内容发送此内容。无法将整数转换为字符串。
非常感谢任何帮助。
答案 0 :(得分:0)
对于任何需要此功能的人都可以,这就是我所做的。工作得很好。不是积极的,这是正确的方式。如果有人有更好的方法或可以改善这一点,请做。
我改变了这个:
LiColumn = MvcHtmlString.Create(webpage.NavColumn), **// needs to be integer**
LiColumnOrder = MvcHtmlString.Create(webpage.NavColumnOrder), **// needs to be integer**
对此:
LiColumn = ((int)(webpage.NavColumn)),
LiColumnOrder = ((int)(webpage.NavColumnOrder)),