It works, however th" /> It works, however th" /> It works, however th"/>

MVC5 Razor Response.Write - text position

2.3k Views Asked by At

I am trying to add a label using Response.Write

<div>
    @if (ViewBag.Message == "1")
    {
            Response.Write(Html.Label("text"));
    }
</div>

It works, however the text shows on the top of the screen not in the correct position, did not have this problem in aspx views.

Would appreciate your suggestions.

2

There are 2 best solutions below

0
Kartikeya Khosla On BEST ANSWER

There is no need of Response.Write() in MVC(MVC is not Webforms) ,just try this code :-

<div>
    @if (ViewBag.Message == "1")
    {
       @Html.Label("text");
    }
</div>
0
RAJIV GIRI On

It is easy and simple.

{
    Response.Write(Label1.Text);
    Label1.Text = "Your Label message here.";
}