ContentResult Kullanımı
Merhabalar, Mvc de view kullanmadan front end tarafına içerik döndürmeye yarayan ContentResult bir ActionResult türüdür. Controller içindeki kullanımı şu şekildedir:
public ContentResult GetContentResultString()
{
return Content("Your content or text");
}
Content metodunun aşağıdaki gibi 3 farklı overload u vardır.
/*
content: Response olarak gönderilecek içerik
contentType: İçerik tipi (MIME type)
contentEncoding: İçerik kodlaması
*/
Content(string content);
Content(string content, string contentType);
Content(string content, string contentType, Encoding contentEncoding);
View.cshtml de veya Layout.cshtml de aşağıdaki gibi PartialView gibi çağrılarak kullanılabilir.
@Html.Action("GetContentResultString","Home")
Kodlamaya devam!