产品模板nopcommerce中的产品评论

时间:2018-03-14 23:17:31

标签: asp.net-mvc nopcommerce nopcommerce-3.90

我尝试添加 Product.Reviews.cshtml ,为用户提供输入以输入他对产品的评论。 Product.Template.Simple.cshtml ,负责查看用户图片产品和所有信息

但是调用的错误不能是一个文件中的两个模型..

  

Product.Template.Simple.cshtml

@model ProductDetailsModel
@using Nop.Core.Domain.Seo;
@using Nop.Core.Infrastructure;
@using Nop.Web.Models.Catalog;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(!String.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Name);
    //meta
    Html.AddMetaDescriptionParts(Model.MetaDescription);
    Html.AddMetaKeywordParts(Model.MetaKeywords);
    //page class
    Html.AppendPageCssClassParts("html-product-details-page");

    var seoSettings = EngineContext.Current.Resolve<SeoSettings>();

    //canonical URL
    if (seoSettings.CanonicalUrlsEnabled)
    {
        var productUrl = Url.RouteUrl("Product", new { SeName = Model.SeName }, this.Request.Url.Scheme);
        Html.AddCanonicalUrlParts(productUrl);
    }

    //open graph META tags
    if (seoSettings.OpenGraphMetaTags)
    {
        Html.AddHeadCustomParts("<meta property=\"og:type\" content=\"product\" />");
        Html.AddHeadCustomParts("<meta property=\"og:title\" content=\"" + Html.Encode(Model.Name) + "\" />");
        Html.AddHeadCustomParts("<meta property=\"og:description\" content=\"" + Html.Encode(Nop.Core.Html.HtmlHelper.StripTags(Model.MetaDescription)) + "\" />");
        Html.AddHeadCustomParts("<meta property=\"og:image\" content=\"" + Model.DefaultPictureModel.ImageUrl + "\" />");
        Html.AddHeadCustomParts("<meta property=\"og:url\" content=\"" + Request.Url.AbsoluteUri + "\" />");
        Html.AddHeadCustomParts("<meta property=\"og:site_name\" content=\"" + Html.Encode(Model.CurrentStoreName) + "\" />");
    }

    //Twitter META tags
    if (seoSettings.TwitterMetaTags)
    {
        Html.AddHeadCustomParts("<meta property=\"twitter:card\" content=\"summary\" />");
        Html.AddHeadCustomParts("<meta property=\"twitter:site\" content=\"" + Html.Encode(Model.CurrentStoreName) + "\" />");
        Html.AddHeadCustomParts("<meta property=\"twitter:title\" content=\"" + Html.Encode(Model.Name) + "\" />");
        Html.AddHeadCustomParts("<meta property=\"twitter:description\" content=\"" + Html.Encode(Nop.Core.Html.HtmlHelper.StripTags(Model.MetaDescription)) + "\" />");
        Html.AddHeadCustomParts("<meta property=\"twitter:image\" content=\"" + Model.DefaultPictureModel.ImageUrl + "\" />");
        Html.AddHeadCustomParts("<meta property=\"twitter:url\" content=\"" + Request.Url.AbsoluteUri + "\" />");
    }
}
<!--product breadcrumb-->
@section Breadcrumb
{
    @Html.Partial("_ProductBreadcrumb", Model.Breadcrumb)
}
@Html.Widget("productdetails_after_breadcrumb", Model.Id)
<div class="page product-details-page">
    <div class="page-body">
        @Html.Widget("productdetails_top", Model.Id)
        @using (Html.BeginRouteForm("Product", new { SeName = Model.SeName }, FormMethod.Post, new { id = "product-details-form" }))
        {
            <div itemscope itemtype="http://schema.org/Product" data-productid="@Model.Id">
                <div class="product-essential">
                    @Html.Widget("productdetails_before_pictures", Model.Id)
                    <!--product pictures-->
                    @Html.Partial("_ProductDetailsPictures", Model)
                    @Html.Widget("productdetails_after_pictures", Model.Id)
                    <div class="overview">
                        @Html.Partial("_Discontinued", Model)
                        <div class="product-name">
                            <h1 itemprop="name">
                                @Model.Name
                            </h1>
                        </div>
                        @if (!String.IsNullOrEmpty(Model.ShortDescription))
                        {
                            <div class="short-description">
                                @Html.Raw(Model.ShortDescription)
                            </div>
                        }
                        @Html.Widget("productdetails_overview_top", Model.Id)
                        <!--product reviews-->
                        @Html.Partial("_ProductReviewOverview", Model.ProductReviewOverview)
                        <!--manufacturers-->
                        @Html.Partial("_ProductManufacturers", Model.ProductManufacturers)
                        <!--availability-->
                        @Html.Partial("_Availability", Model)
                        <!--SKU, MAN, GTIN, vendor-->
                        @Html.Partial("_SKU_Man_GTIN_Ven", Model)
                        <!--delivery-->
                        @Html.Partial("_DeliveryInfo", Model)
                        <!--sample download-->
                        @Html.Partial("_DownloadSample", Model)
                        <!--attributes-->
                        @{
                            var dataDictAttributes = new ViewDataDictionary();
                            dataDictAttributes.TemplateInfo.HtmlFieldPrefix = string.Format("attributes_{0}", Model.Id);
                            @Html.Partial("_ProductAttributes", Model.ProductAttributes, dataDictAttributes)
                        }
                        <!--gift card-->
                        @{
                            var dataDictGiftCard = new ViewDataDictionary();
                            dataDictGiftCard.TemplateInfo.HtmlFieldPrefix = string.Format("giftcard_{0}", Model.Id);
                            @Html.Partial("_GiftCardInfo", Model.GiftCard, dataDictGiftCard)
                        }
                        <!--rental info-->
                        @{
                            var dataDictRental = new ViewDataDictionary();
                            dataDictRental.TemplateInfo.HtmlFieldPrefix = string.Format("rental_{0}", Model.Id);
                            @Html.Partial("_RentalInfo", Model, dataDictRental)
                        }
                        <!--price & add to cart-->
                        @{
                            var dataDictPrice = new ViewDataDictionary();
                            dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", Model.Id);
                            @Html.Partial("_ProductPrice", Model.ProductPrice, dataDictPrice)

                            @Html.Partial("_ProductTierPrices", Model.TierPrices)

                            var dataDictAddToCart = new ViewDataDictionary();
                            dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", Model.Id);
                            @Html.Partial("_AddToCart", Model.AddToCart, dataDictAddToCart)
                        }
                        <!--wishlist, compare, email a friend-->
                        <div class="overview-buttons">
                            @Html.Widget("productdetails_inside_overview_buttons_before", Model.Id)
                            @{
                                var dataDictAddToWishlist = new ViewDataDictionary();
                                dataDictAddToWishlist.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", Model.Id);
                                @Html.Partial("_AddToWishlist", Model.AddToCart, dataDictAddToWishlist)
                            }
                            @Html.Partial("_CompareProductsButton", Model)
                            @Html.Partial("_ProductEmailAFriendButton", Model)
                            @Html.Widget("productdetails_inside_overview_buttons_after", Model.Id)
                        </div>
                        @Html.Partial("_ShareButton", Model)
                        @Html.Widget("productdetails_overview_bottom", Model.Id)
                    </div>
                    @if (!String.IsNullOrEmpty(Model.FullDescription))
                    {
                        <div class="full-description" itemprop="description">
                            @Html.Raw(Model.FullDescription)
                        </div>
                    }
                </div>
                @Html.Widget("productdetails_before_collateral", Model.Id)
                <div class="product-collateral">
                    @Html.Partial("_ProductSpecifications", Model.ProductSpecifications)
                    @Html.Partial("_ProductTags", Model.ProductTags)
                </div>
                @Html.Action("ProductsAlsoPurchased", "Product", new { productId = Model.Id })
                @Html.Action("RelatedProducts", "Product", new { productId = Model.Id })
            </div>
        }
        @Html.Widget("productdetails_bottom", Model.Id)
    </div>
</div>
  

Product.Reviews.cshtml

@model ProductReviewsModel
@using Nop.Web.Models.Catalog;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(Model.ProductName);
    Html.AddTitleParts(T("PageTitle.ProductReviews").Text);
    //page class
    Html.AppendPageCssClassParts("html-product-reviews-page");
}
<div class="page product-reviews-page">
    <div class="page-title">
        <h1>@T("Reviews.ProductReviewsFor") <a href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })">@Model.ProductName</a></h1>
    </div>
    <div class="page-body">
        @Html.Widget("productreviews_page_top", Model.ProductId)
        @if (Model.AddProductReview.SuccessfullyAdded)
        {
            <div class="result">
                @Model.AddProductReview.Result
            </div>
        }
        else
        {
            <div class="write-review" id="review-form">
                <div class="title">
                    <strong>@T("Reviews.Write")</strong>
                </div>
                @using (Html.BeginForm())
                {
                    @Html.AntiForgeryToken()
                    var validationSummary = Html.ValidationSummary(true);
                    if (!MvcHtmlString.IsNullOrEmpty(validationSummary))
                    {
                        <div class="message-error">@validationSummary</div>
                    }
                    <div class="fieldset">
                        <div class="form-fields">
                            <div class="inputs">
                                @Html.LabelFor(model => model.AddProductReview.Title, new { }, ":")
                                @Html.TextBoxFor(model => model.AddProductReview.Title, Model.AddProductReview.CanCurrentCustomerLeaveReview ? (object)(new { @class = "review-title" }) : (object)(new { @class = "review-title", disabled = "disabled" }))
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.AddProductReview.Title)
                            </div>
                            <div class="inputs">
                                @Html.LabelFor(model => model.AddProductReview.ReviewText, new { }, ":")
                                @Html.TextAreaFor(model => model.AddProductReview.ReviewText, Model.AddProductReview.CanCurrentCustomerLeaveReview ? (object)(new { @class = "review-text" }) : (object)(new { @class = "review-text", disabled = "disabled" }))
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.AddProductReview.ReviewText)
                            </div>
                            <div class="review-rating">
                                @Html.LabelFor(model => model.AddProductReview.Rating, new { }, ":")
                                <ul>
                                    <li class="label first">@T("Reviews.Fields.Rating.Bad")</li>
                                    <li class="rating-options">
                                        @Html.RadioButtonFor(model => model.AddProductReview.Rating, "1", new { id = "addproductrating_1" })
                                        @Html.RadioButtonFor(model => model.AddProductReview.Rating, "2", new { id = "addproductrating_2" })
                                        @Html.RadioButtonFor(model => model.AddProductReview.Rating, "3", new { id = "addproductrating_3" })
                                        @Html.RadioButtonFor(model => model.AddProductReview.Rating, "4", new { id = "addproductrating_4" })
                                        @Html.RadioButtonFor(model => model.AddProductReview.Rating, "5", new { id = "addproductrating_5" })
                                    </li>
                                    <li class="label last">@T("Reviews.Fields.Rating.Excellent")</li>
                                </ul>
                            </div>
                            @if (Model.AddProductReview.DisplayCaptcha)
                            {
                                <div class="captcha-box">
                                    @Html.Raw(Html.GenerateCaptcha())
                                </div>
                            }
                        </div>
                    </div>
                    <div class="buttons">
                        <input type="submit" name="add-review" class="button-1 write-product-review-button" value="@T("Reviews.SubmitButton")" />
                    </div>
                }
            </div>
        }
        @if (Model.Items.Count > 0)
        {
            <div class="product-review-list">
                <div class="title">
                    <strong>@T("Reviews.ExistingReviews")</strong>
                </div>
                @foreach (var review in Model.Items)
                {
                    int ratingPercent = review.Rating * 20;
                    <div class="product-review-item">
                        <div class="review-item-head">
                            <div class="review-title">
                                <strong>@review.Title</strong>
                            </div>
                            <div class="product-review-box">
                                <div class="rating">
                                    <div style="width: @(ratingPercent)%">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="review-content">
                            <div class="review-text">
                                @Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(review.ReviewText, false, true, false, false, false, false))
                            </div>
                            <div class="review-info">
                                <span class="user">
                                    <label>@T("Reviews.From"):</label>
                                    @if (review.AllowViewingProfiles)
                                    {
                                        <a href="@Url.RouteUrl("CustomerProfile", new { id = review.CustomerId })">@(review.CustomerName)</a>
                                    }
                                    else
                                    {
                                        @review.CustomerName
                                    }
                                </span>
                                <span class="separator">|</span>
                                <span class="date">
                                    <label>@T("Reviews.Date"):</label>
                                    <span>@review.WrittenOnStr</span>
                                </span>
                            </div>
                            @Html.Partial("_ProductReviewHelpfulness", review.Helpfulness, new ViewDataDictionary())
                            @Html.Widget("productreviews_page_inside_review", review.Id)
                            @if (!String.IsNullOrEmpty(review.ReplyText))
                            {
                                <div class="reply">
                                    <div class="reply-header">
                                        @T("Reviews.Reply")
                                    </div>
                                    <div class="reply-text">
                                        @Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(review.ReplyText, false, true, false, false, false, false))
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                }
            </div>
        }
        @Html.Widget("productreviews_page_bottom", Model.ProductId)
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

您无法在视图页面中放置两个模型,导致只调用一个模型并与控制器操作交互。 您应该将其用作局部视图。 但正如我完全知道的那样,nopcommerce默认显示产品页面中的客户评论。 尝试启用该

的设置