render a string in MVC just like rendering a view, possible?
is it possible to render a string like this:
public ActionResult Do(){
s = " hello, click here <%=Html.ActionLink(\"index\",\"index\") %> ";
return Content(RenderString(s));
}
the result would something like this:
hello, click here开发者_如何转开发 <a href="/home/index">index</a>
What is the purpose of this? You have a controller action which tries to evaluate some string WebForms syntax string and return it as content. Why not simply return the view and have this view do the job?
If you want dynamic to have views (coming from a database or something) you could write a custom view engine and personalize their location so that your action looks like this:
public ActionResult Do()
{
return View();
}
and the corresponding view contents will be fetched from your custom view engine instead of the standard file locations.
If you want to render the contents of a view into a string this has been covered in many blog posts. Finally if you are dealing with sending views as emails there are probably better solutions.
So depending on what you are trying to achieve there might be different solutions.
public String Do(){
string s = " hello, click <a href='" + Url.Action("Index") +"' > here </a>";
return s;
}
then if you call {Controller}/Do you will have your string
EDITED
Marco
精彩评论