モデルバインディングの問題が発生しました。My IDのタイプはSitecore.Data.IDです。フォームを送信した後、他のフィールドはすべて正しいデータで結合されますが、IDは別のものに変更されます。モデルバインディングが正しく動作しません。フォームを使用して送信しているときに、Sitecore.Data.IDタイプが返されます。
たとえば、非表示フィールド 'id'の値が2fb3169c-8b3f-4618-ac78-6170fd0eb297
で、CartControllerにサブミットした後、値は{{68CE2980-7611-422B-96E1-29C4CC0132D5}}
または{{82F7914C-34D6-4009-B301-53C1499774A3}}
などになります。
私はそのランダムだと思います。どこが間違っているのか分かりません。
私はこのようなモデルがあります:
[SitecoreType(AutoMap = true,Cachable = true)]
public class Book : Item
{
public virtual ID Id { get; set; }
[SitecoreField(IsRequired = true)]
public virtual string Name { get; set; }
[SitecoreField(IsRequired = true)]
public virtual double Price { get; set; }
[SitecoreField(IsRequired = true)]
[StringLength(50, MinimumLength = 5)]
public virtual string Description { get; set; }
}
これが私の見解です:
@model Book
using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post)
)
{
@Html.Sitecore().FormHandler("Cart", "Index")
@Html.HiddenFor(x => Model.Id)
<div>
@Html.DisplayFor(x => book.Name)
@Html.EditorFor(x => book.Name, new { @class = "bold" })
</div>
<div>
@Html.DisplayFor(x => book.Price)
@Html.EditorFor(x => book.Price, new { @class = "bold" })
</div>
<div>
@Html.DisplayFor(x => book.Description)
@Html.EditorFor(x => book.Description, new { @class = "bold" })
</div>
<input type="submit" />
}
これは、カート・コントローラです:
public class CartController : GlassController
{
[HttpPost]
public ActionResult Index(Book book)
{
string id = book.Id.ToString();
if (!string.IsNullOrEmpty(id))
{
book = SitecoreContext.GetItem<Book>(new Guid(id), false, true);
return PartialView("~/Views/Cart/details.cshtml", book);
}
return Redirect("http://google.com");
}
}
@HishaamNamooya私はデバッグを行なったし、本はフィールドの値をオブジェクト結合後に発見されました。 Guid部分は後の段階です。 –
IdをCartIdに変更しても、引き続き問題が発生しますか? –
@HishaamNamooyaいいえ、まだIdのためのランダムな値を得て、それは動作しませんでした。 –