PDA

View Full Version : [CLOSED] [Razor] Using Model in MVC View



UnifyEducation
May 02, 2012, 9:16 AM
Hello,

Could you give me an example for using Model in MVC View
I had tried:


@Html.X().Label().Text(@<text>@Model.Pageheading</text>)

But this doesn't work


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type

Vladimir
May 02, 2012, 12:43 PM
I guess it should be


@Html.X().Label().Text(Model.Pageheading)

Daniil
May 02, 2012, 12:52 PM
Hi,

I think it should look just

@Html.X().Label().Text(Model.Pageheading)


Here is an example.

Example View

@inherits System.Web.Mvc.WebViewPage<DateTime>

<!DOCTYPE html>

<html>
<head>
<title>Ext.NET Razor Example</title>
</head>
<body>
@Html.X().ResourceManager()

@(Html.X().Label()
.Text("The current time is " + Model.ToShortTimeString())
)
</body>
</html>

Example Controller Action

public ActionResult TestRazor()
{
return View(DateTime.Now);
}

UnifyEducation
May 02, 2012, 4:38 PM
Thank you, it works now