ASP.NET MVC using response.write not working

1k Views Asked by At

Can anyone tell how to write you own method and call it view or simply write "Hello world" in the following manner? This is what I tried to write on my

Index.cshtml:

<h1>
    Hello,
    <span>
        @{ HttpContext.Current.Response.Write("World!"); }
    </span>
</h1>

but it is not working? Thanks for any help :)

1

There are 1 best solutions below

5
On

Response.Write is use for write string content to the responce,

If you want to bind your test to the view than you can create a model for the view and initialize from controller and pass it to the view see below example,

Here my model is type of string, you can create your complax model if thare are more than one property

Controller:

public ActionResult Index()
{
   return View("index","World!");
}

View:

@model string
<h1>
    Hello,
    <span>
        @Model
    </span>
</h1>