У меня есть модель с этим свойством:
[AllowHtml]
[DisplayName("Widget for Table")]
[StringLength(1000, ErrorMessage = "Maximum chars 1000")]
[DataType(DataType.Html)]
public object TableWidget { get; set; }
А вот методы создания в контроллере:
//
// GET: /Admin/Table/Create
public ActionResult Create(int id)
{
Season season = _seasonRepository.GetSeason(id);
var table = new Table
{
SeasonId = season.SeasonId
};
return View(table);
}
//
// POST: /Admin/Table/Create
[HttpPost]
public ActionResult Create(Table a)
{
if (ModelState.IsValid)
{
_tableRepository.Add(a);
_tableRepository.Save();
return RedirectToAction("Details", "Season", new { id = a.SeasonId });
}
return View();
}
И последнее вот мое мнение:
@model Stridh.Data.Models.Table
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.TableURL)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TableURL) @Html.ValidationMessageFor(model => model.TableURL)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SortOrder)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SortOrder) @Html.ValidationMessageFor(model => model.SortOrder)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.TableWidget)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TableWidget) @Html.ValidationMessageFor(model => model.TableWidget)
</div>
<div class="editor-label invisible">
@Html.LabelFor(model => model.SeasonId)
</div>
<div class="editor-field invisible">
@Html.EditorFor(model => model.SeasonId)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
Когда я добавляю «обычное» сообщение без html, все сохраняется ОК, но при сохранении выдает потенциально опасный запрос. Форма ...
Другая странная вещь заключается в том, что я заставил этот [AllowHtml] работать в другом классе моделей. Я не могу найти, почему это вызывает у меня проблемы. Нужна ваша помощь. : -)