In this article, I will show to how to return a string result using ActionResult in mvc 4. You can achieve this by ContentResult to return a string. It will create content result object by using a string.
Controller Action Method:
public ActionResult GetHtmlPage(string path)
{
string strHTML = System.IO.File.ReadAllText(Server.MapPath(path));
return Content(strHTML);
}
View:
<div class="panel" >
@Html.Action("GetHtmlPage", "LoadHtml", new { path = "~/practice/dialog.html" })
</div>
I created an html file and named as dialog.html and going to return as string result using ActionResult for html page in asp.net MVC.
Dialog.html:
<body>
<div id="dialog">
<header>A dialog box of some description</header>
Lorem ipsum etc, etc.
<footer>
<button>Ok</button></footer>
</div> </body>
Output:
Post your comments / questions
Recent Article
- How to get domain name information from a Domain using Python
- ModulenotFoundError: no module named 'debug_toolbar' -SOLUTION
- How to create superuser in django project hosted in cPanel without terminal
- CSS & images not loading in django admin | cpanel without terminal
- Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
- How to sell domain name on Godaddy (2023)
- TemplateSyntaxError at / Could not parse the remainder: ' + 1' from 'forloop.counter0 + 1'
- urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0
Related Article