Mam dodane Tinymce w widoku. Zapisuje do bazy danych i próbuje go wyświetlić w innej stronie. Niestety nie działa mi to.
Proszę o rady, pomoc, nakierowanie.
Do testów nie dodałem sprawdzania kodu pod kątem złośliwości. Wpierw chcę się nauczyć dobrze to obsługiwać.
Kod: (obszerny)
// Model
public class Edytor
{
public int Id { get; set; }
[AllowHtml]
public string Tresc { get; set; }
}
// Kontekst
public DbSet<Edytor> Edytor { get; set; }
//
Create/Add kontroler
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(false)]
public ActionResult Create([Bind(Include = "Id,Tresc")] Edytor edytor)
{
if (ModelState.IsValid)
{
db.Edytor.Add(edytor);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(edytor);
}
Create/dodaj widok
@model WebApplication2.Models.Edytor
@{
ViewBag.Tytul = "Edytuj treść HTML";
}
<h2>Edytuj treść HTML</h2>
<div class="row" style="max-width:800px">
<div class="col-xs-12">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<input type="hidden" name="Id" value="Model.Id" />
<hr />
<h2>Kod HTML:</h2>
@Html.TextAreaFor(model => model.Tresc)
<div class="form-actions align-right clearfix">
<button type="submit" class="btn btn-primary pull-left">
<i class="ace-icon fa fa-check bigger-110"></i>
Zapisz
</button>
</div>
}
@*@if (Model != null)
{
<hr />
<h2>Podgląd w HTMLu:</h2>
<hr />
@Html.Raw(Model.Tresc);
}*@
</div>
</div>
A to co zostało dodane chcę wyświetlić w innym miejscu lub w ogóle poza tym blokiem.
// Widok
@model WebApplication2.Models.Edytor
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<p>Use this area to provide additional information.</p>
@if (Model == null)
{
<h1>NULL</h1>
}
@if (Model != null)
{
@Html.Raw(Model.Tresc)
}
code>
```csharp
// Kontoler
ApplicationDbContext context = new ApplicationDbContext();
Edytor e = context.Edytor.Find(0);
return View(e);
Nie wyświetla się. Próbowałem dodać FirstOrDeafult to rzuca nulle.