есть 2 способа вернуть строку из контроллера в представление
первый
вы можете вернуть только строку, но не будете включены в HTML
файл будет отображаться в строке браузера
секунда
может вернуть строку как объект результата просмотра
вот примеры кода для этого
public class HomeController : Controller
{
// GET: Home
// this will mreturn just string not html
public string index()
{
return "URL to show";
}
public ViewResult AutoProperty()
{ string s = "this is a string ";
// name of view , object you will pass
return View("Result", (object)s);
}
}
в файле просмотра для запуска AutoProperty он перенаправит вас на Результат просмотра и отправит s
код для просмотра
<!--this to make this file accept string as model-->
@model string
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Result</title>
</head>
<body>
<!--this is for represent the string -->
@Model
</body>
</html>
я запускаю его на http://localhost:60227/Home/AutoProperty