问题描述
在我的剃须刀视图中的“面板区域-按住评论按钮”中,我尝试引用视图模型属性BlogPublishedByBlogId.BlogId,但得到-“名称BlogPublishedByBlogId在当前上下文中不存在”。
但是,我可以使用Lamda很好地引用其他属性:model => model.BlogPublishedByBlogId.CreatedDateTime
如何在“面板区域-按住评论按钮”区域中引用“ blogId”?
@model GbngWebClient.Models.BlogPublishedByBlogIdVM
<h2 class="page-header"><span class="blogtitle">@Session["BlogTitle"]</span></h2>
@{
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
@if (Model != null)
{
<div class="panel panel-default toppanel">
<div class="panel-body">
<div class="row">
<div class="col-md-2">
@Html.LabelFor(model => model.BlogPublishedByBlogId.CreatedDateTime)
@Html.TextBoxFor(model => model.BlogPublishedByBlogId.CreatedDateTime,new { @class = "form-control",@disabled = "disabled" })
</div>
<div class="col-md-2">
@Html.LabelFor(model => model.BlogPublishedByBlogId.ModifiedDateTime)
@Html.TextBoxFor(model => model.BlogPublishedByBlogId.ModifiedDateTime,@disabled = "disabled" })
</div>
</div>
<br />
<div class="row">
<div>
@Html.TextAreaFor(model => model.BlogPublishedByBlogId.BlogContent,new { @class = "form-control blogContent",@disabled = "disabled" })
</div>
</div>
</div>
@* Panel area - to hold the comment button. *@
<div class="panel-footer">
<button type="button" class="btn btn-default Comment" data-id="BlogPublishedByBlogId.BlogId" value="Comment">
<span class="glyphicon glyphicon-comment" aria-hidden="true"></span> Get Comment(s)
</button>
</div>
<div id="@string.Format("{0}_{1}","commentsBlock",BlogPublishedByBlogId.BlogId)" style="border: 1px solid #f1eaea; background-color: #eaf2ff;">
<div class="AddCommentArea" style="margin-left: 30%; margin-bottom: 5px; margin-top: 8px;">
<input type="text" id="@string.Format("{0}_{1}","comment",BlogPublishedByBlogId.BlogId)" class="form-control" placeholder="Add a Comment about the blog..." style="display: inline;" />
<button type="button" class="btn btn-default addComment" data-id="BlogPublishedByBlogId.BlogId"><span class="glyphicon glyphicon-comment" aria-hidden="true"></span></button>
</div>
</div>
</div>
}
视图模型:
namespace GbngWebClient.Models
{
public class BlogPublishedByBlogIdVM
{
public BlogPublishedByBlogIdVM()
{
this.BlogPublishedByBlogId = new BlogPublishedByBlogId();
}
public BlogPublishedByBlogId BlogPublishedByBlogId { get; set; }
}
}
解决方法
我在@的前面添加了@Model: BlogPublishedByBlogId.BlogId。