Hello i am creating a small webpage that give our users an interface to search in our database.
This website must supply 2 webservice functions, Search(string searchString) and GetAccountInfoByInitials(string initials)
I would like to use my controllers to do this, but i can not find out how i can get the html out of a ViewResult.
I have tryed the following, but the result.ToString() only give me the string "System.Web.Mvc.ViewResult"
public class SearchService : ISearchService
{
private readonly ServiceHandlerController _controller;
public SearchService()
{
_controller = new ServiceHandlerController();
}
public string Search(string searchString)
{
var result = _controller.Search(searchString);
return result.ToString();
}
public string GetAccountInfoByInitials(string initials)
{
var result = _controller.Search(initials).ToString();
return result;
}
}
The View Result doesn't holds the page by itself. Asp.net MVC uses it, along with the View Engine configured to get the actual page.
You'll hit a roadblock if you are using the default view engine - see link text. Basically because the asp.net view engine is tied to the context. Other view engines won't give you this issue, but if the assets you are trying to reduce are already relying in the default view engine then that defeats the purpose. There are other ways around it, but I'm unsure how convenient those would be for you.
I do this in almost an identical fashion but actually use the controller iteself to return a partialview to string.
i use the following extension method in my base controller:
followed by then returning my partialview in the following fashion:
This should hopefully sort you out.
This is an answer to a question I posted similar to this one: Is there a way to process an MVC view (aspx file) from a non-web application?
Then, to render a file: