May 11, 2012, 3:09 PM
[CLOSED] Razor, X.Msg.Notify during a DirectEvent and ResourceManager
Hi,
I am trying to create an MVC version of the example page that comes with the NuGet package.
The bit to create the window with the text area and button is straight forward enough:
View:
But when I call the direct event, that is when I run into trouble; I can't seem to create the Notify on the server side. First I tried to create a simple strongly typed View which just registered the resource manager again and try to find a @Html.X().Msg or Notify or similar but couldn't see one. So then I tried to create a response script inside the controller action:
This is caused by my instance of Notification doing a .ToScript(); it is looking for a resource manager but can't find one, even if I have a View with just this:
Of course, I could get around this altogether by not making a Direct Event just to show the message the user typed and keeping it all on the client as it should be, but I am just trying to show the example that comes with NuGet as an MVC/Razor example. Also perhaps more realistically in the future I will want to create more complex layouts, grids, tabs, trees etc all on the fly using Direct Events or Direct Methods so it would still be useful to know where I am going wrong.
I am probably missing the obvious :)
I am trying to create an MVC version of the example page that comes with the NuGet package.
The bit to create the window with the text area and button is straight forward enough:
View:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>DirectEventExample</title>
</head>
<body>
@Html.X().ResourceManager().Theme(Theme.Gray)
@(Html.X().Window()
.Title("Welcome to Ext.NET 2.0")
.Height(215)
.Width(350)
.BodyPadding(5)
.DefaultButton("0")
.Layout("AnchorLayout")
.DefaultAnchor("100%")
.Items(items => items.Add(Html.X()
.TextArea()
.EmptyText(">> Enter a Message Here <<")
.FieldLabel("Test Message")
.Height(85))
)
.Buttons(buttons => buttons.Add(Html.X()
.Button()
.Text("Submit")
.Icon(Icon.Accept)
.DirectEvents(directEvents => directEvents.Click.Url = "/DirectEventMessage/")
)
))
</body>
</html>
Controller:public class DirectEventExampleController : Controller
{
//
// GET: /DirectEventExample/
public ActionResult Index()
{
return View();
}
}
That is all fine and it renders the same message box that your NuGet package installs by default.But when I call the direct event, that is when I run into trouble; I can't seem to create the Notify on the server side. First I tried to create a simple strongly typed View which just registered the resource manager again and try to find a @Html.X().Msg or Notify or similar but couldn't see one. So then I tried to create a response script inside the controller action:
public class DirectEventMessageController : Controller
{
//
// GET: /DirectEventMessage/
public ActionResult Index(string message)
{
var config = new NotificationConfig
{
Icon = Icon.Accept,
Title = "Working",
Html = message
};
string script = X.Msg.Notify(config).ToScript();
return new AjaxResult(script);
}
}
If I run the above, I get a run time error sayingObject reference not set to an instance of an object
at Ext.Net.Notification.ToScript() +47This is caused by my instance of Notification doing a .ToScript(); it is looking for a resource manager but can't find one, even if I have a View with just this:
@{
Layout = null;
}
@Html.X().ResourceManager()
Admittedly what I am trying feels wrong; I shouldn't be recreating another resource manager on the Direct Event click as there is already one on the page, but I guess I need to create a dummy/proxy one just so a script can be created and other server side code relying on it (to use things like RegisterIcon etc) will work... Trying to create it inside the Controller didn't work either (unless I didn't instantiate it properly)Of course, I could get around this altogether by not making a Direct Event just to show the message the user typed and keeping it all on the client as it should be, but I am just trying to show the example that comes with NuGet as an MVC/Razor example. Also perhaps more realistically in the future I will want to create more complex layouts, grids, tabs, trees etc all on the fly using Direct Events or Direct Methods so it would still be useful to know where I am going wrong.
I am probably missing the obvious :)
Last edited by Daniil; May 14, 2012 at 7:48 AM.
Reason: [CLOSED]