nopcommerce オープン ソースを使用しています。そのため、別のテーブルを追加し、Product Variant に別のタブを追加したいと考えています。
だから私はモデルを作成します。
public partial class ProductVariantPriceRangeModel : BaseNopEntityModel
{
public int ProductVariantId { get; set; }
[NopResourceDisplayName("Admin.Catalog.Products.Variants.ProductVariantPriceRange.Fields.SpecialPriceStartDate")]
[DisplayFormat(NullDisplayText = "", DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime? SpecialPriceStartDate { get; set; }
[NopResourceDisplayName("Admin.Catalog.Products.Variants.ProductVariantPriceRange.Fields.SpecialPriceEndtDate")]
[DisplayFormat(NullDisplayText = "", DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime? SpecialPriceEndtDate { get; set; }
[NopResourceDisplayName("Admin.Catalog.Products.Variants.ProductVariantPriceRange.Fields.Price")]
public decimal Price1 { get; set; }
}
これが私のコントローラーです。
[HttpPost, GridAction(EnableCustomBinding = true)]
public ActionResult ProductVariantPriceRangeList(GridCommand command, int productVariantId)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var productVariant = _productService.GetProductVariantById(productVariantId);
if (productVariant == null)
throw new ArgumentException("No product variant found with the specified id");
var productVariantPriceRange = productVariant.ProductVariantPriceRange;
var productVariantPriceRangeModel = productVariantPriceRange
.Select(x =>
{
return new ProductVariantModel.ProductVariantPriceRangeModel()
{
Id = x.Id,
ProductVariantId = x.ProductVariantId,
SpecialPriceStartDate = x.SpecialPriceStartDate,
SpecialPriceEndtDate=x.SpecialPriceEndtDate,
Price1 = x.SpecialPrice
};
})
.ToList();
var model = new GridModel<ProductVariantModel.ProductVariantPriceRangeModel>
{
Data = productVariantPriceRangeModel,
Total = productVariantPriceRangeModel.Count
};
return new JsonResult
{
Data = model
};
}
これが私の見解です。
@model ProductVariantModel
@using Telerik.Web.Mvc.UI;
@using Nop.Core.Domain.Catalog;
@using Nop.Admin;
@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.ProductId)
@Html.Telerik().TabStrip().Name("productvariant-edit").Items(x =>
{
x.Add().Text(T("Admin.Catalog.Products.Variants.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
x.Add().Text(T("Admin.Catalog.Products.Variants.TierPrices").Text).Content(TabTierPrices().ToHtmlString());
x.Add().Text(T("Admin.Catalog.Products.Variants.ProductVariantAttributes").Text).Content(TabProductVariantAttributes().ToHtmlString());
x.Add().Text(T("Admin.Catalog.Products.Variants.Discounts").Text).Content(TabDiscounts().ToHtmlString());
x.Add().Text(T("Admin.Catalog.Products.Variants.ProductVariantPriceRange").Text).Content(TabProductVariantPriceRange().ToHtmlString());
//generate an event
EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "productvariant-edit"));
})
@helper TabProductVariantPriceRange()
{
if (Model.Id > 0)
{
@(Html.Telerik().Grid<ProductVariantModel.ProductVariantPriceRangeModel>()
.Name("productVariantPriceRange-grid")
.DataKeys(keys =>
{
keys.Add(x => x.Id);
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax()
.Select("ProductVariantPriceRangeList", "ProductVariant", new { productVariantId = Model.Id })
.Insert("ProductVariantPriceRangeInsert", "ProductVariant", new { productVariantId = Model.Id })
.Update("ProductVariantPriceRangeUpdate", "ProductVariant")
.Delete("ProductVariantPriceRangeDelete", "ProductVariant");
})
.Columns(columns =>
{
columns.Bound(x => x.ProductVariantId)
.Width(100).ReadOnly()
.Centered();
columns.Bound(x => x.SpecialPriceStartDate)
.Width(200)
.Centered();
//columns.Bound(x => x.SpecialPriceEndtDate)
// .Width(200)
// .Centered();
columns.Bound(x => x.Price1)
.Width(100);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
})
.Width(180);
})
.ToolBar(commands => commands.Insert())
.ClientEvents(events => events.OnEdit("onTierPriceEdit"))
.EnableCustomBinding(true))
}
else
{
@T("Admin.Catalog.Products.Variants.ProductVariantPriceRange.SaveBeforeEdit")
}
}
プログラマーを実行すると、エラーが発生します..
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
Source Error:
Line 83: if (Model.Id > 0)
Line 84: {
Line 85: @(Html.Telerik().Grid<ProductVariantModel.ProductVariantPriceRangeModel>()
Line 86: .Name("productVariantPriceRange-grid")
Line 87: .DataKeys(keys =>
どうすれば解決できますか??
ありがとう