Merhabalar,
Başlıkta belirtmiş olduğum hatayı alıyorum. Yanlış yapılan yer neresidir acaba? Yardımcı olabilir misiniz?
Controller:
Başlıkta belirtmiş olduğum hatayı alıyorum. Yanlış yapılan yer neresidir acaba? Yardımcı olabilir misiniz?
Controller:
Kod:
[HttpGet]
public IActionResult Add()
{
CategoryManager cm = new CategoryManager(new EFCategoryRepo());
List<SelectListItem> categorievalue = (from x in cm.GetList()
select new SelectListItem
{
Text = x.CategoryName,
Value = x.CategoryId.ToString()
}).ToList();
ViewBag.cm = categorievalue;
return View();
}
[HttpPost]
public IActionResult Add(Article a )
{
CategoryManager cm = new CategoryManager(new EFCategoryRepo());
ArticleValidator av = new ArticleValidator();
ValidationResult result = av.Validate(a);
if (result.IsValid)
{
a.ArticleStatus = true;
a.ArticleCreatedDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
return RedirectToAction("Index", "Blog" );
}
else
{
foreach (var item in result.Errors)
{
ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
}
}
return View();
}
View Tarafı :
@model BlogEntity.Concrete.Article
@{
ViewData["Title"] = "Add";
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<br />
<h2>Yeni Blog Ekle</h2>
<br />
@using (Html.BeginForm("Add", "Blog", FormMethod.Post))
{
<h4>Blog Adı</h4>
@Html.TextBoxFor(x => x.ArticleTitle, new { [USER=193939]@Class[/USER] = "form-control" })
@Html.ValidationMessageFor(x => x.ArticleTitle, "", new { [USER=193939]@Class[/USER] = "text-danger" })
<br />
<h4>Blog Açıklama</h4>
@Html.TextAreaFor(x => x.ArticleContent, 7, 3, new { [USER=193939]@Class[/USER] = "form-control" })
@Html.ValidationMessageFor(x => x.ArticleContent, "", new { [USER=193939]@Class[/USER] = "text-danger" })
<br />
<h4>Blog Kategorisi</h4>
@Html.DropDownListFor(x => x.CategoryId, (List<SelectListItem>)ViewBag.cm, new { [USER=193939]@Class[/USER] = "form-control" })
@Html.ValidationMessageFor(x => x.CategoryId,"", new { [USER=193939]@Class[/USER] = "text-danger" })
<br />
@*<h4>Blog Resmi</h4>
@Html.TextBoxFor(x => x.ArticleImage, new { [USER=193939]@Class[/USER] = "form-control" })
@Html.ValidationMessageFor(x => x.ArticleImage, "", new { [USER=193939]@Class[/USER] = "text-danger" })
<br />*@
<button class="btn btn-info">Blog Ekle</button>
<input type="button" class="btn btn-danger" value="Geri Dön" onclick="location.href = '@Url.Action("Index","Blog")'" />
}