first sorry for my bad english, it's not my first language [;)]
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult Draw(int width, int height)
{
AddTask.Assign("#mapContainer > div", View("Map", Fields));
AddTask.Call("map.initialize");
return Json(AjaxHandler.GetResponse());
}
To work with Ajax I have wrote my own class.
After building an object using AddTask (line 4 and 5) I want to return this object as Json (line 7).
But to get this work done I need to transform the ViewResult from View("Map", Fields) (line 4) to a string. Is this possible?
Thanks, Markus
Edit: Maybe a bit more understandable... I want to to something like this:
string content = View("Map");
It is obvious to me, that this doesn't works. But I really need something like this. I need the functionality to store a rendered View or PartialView in a variable... is this possible?
Try the properties of the View("Map", Fields) ViewResult --> there's a View property (an IView) which allows you to render contents to any TextWriter. StringWriter might be a good choice to actually render the IView to a string which can be used. Good luck!
Visit my blog at http://blog.maartenballiauw.be
Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
I think you mean this one? Seemingly this could help... but I allready searched a way to get the current ViewContext for useing in the Controller and I couldn't found one. Did you or sombody else know a solution to do so?
n26
0 Points
2 Posts
Getting ViewResult as String?
Oct 31, 2008 08:58 AM|LINK
Hello,
first sorry for my bad english, it's not my first language [;)]
To work with Ajax I have wrote my own class.
After building an object using AddTask (line 4 and 5) I want to return this object as Json (line 7).
But to get this work done I need to transform the ViewResult from View("Map", Fields) (line 4) to a string. Is this possible?
Thanks,
Markus
Edit:
Maybe a bit more understandable...
I want to to something like this:
It is obvious to me, that this doesn't works. But I really need something like this. I need the functionality to store a rendered View or PartialView in a variable... is this possible?
MVC json ajax ViewResult
maartenba
Member
368 Points
76 Posts
Re: Getting ViewResult as String?
Oct 31, 2008 02:48 PM|LINK
Try the properties of the View("Map", Fields) ViewResult --> there's a View property (an IView) which allows you to render contents to any TextWriter. StringWriter might be a good choice to actually render the IView to a string which can be used. Good luck!
Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
n26
0 Points
2 Posts
Re: Getting ViewResult as String?
Oct 31, 2008 03:36 PM|LINK
First, thanks for your answere!
I think you mean this one? Seemingly this could help... but I allready searched a way to get the current ViewContext for useing in the Controller and I couldn't found one. Did you or sombody else know a solution to do so?
Thanks,
Markus