0

I have searched SO for my scenario but no success. I have a problem statement that I need to show different kinds of reports based on user input. And the reports are varied based on logged in user's location. So, I am storing the view (cshtml) code in DB and want to return the code by calling stored procedure passing required parameters. Here, I do not know how to bind the model to the returned view string (came from DB). Can I write custom HTML helpers and solve this? Is there any other way to achieve this? Any kind of help would be appreciated. Thank you.

Mahesh Kudikala
  • 187
  • 1
  • 6
  • You have to create a blank view and render your view page string which was come for DB into the same view and then after you can call your modal to display your string view. Every view (Exclude - partial) required server action for render so you need to create one blank view for all returned string. – Krishnakumar Patel Apr 10 '19 at 06:27
  • @KrishnaPatel thanks, I will try it. – Mahesh Kudikala Apr 10 '19 at 08:01
  • @KrishnaPatel, I tried it by creating a blank view in an action like this: public ActionResult Test(){string str = ""at"inherits System.Web.Mvc.WebViewPage "at"model WebApplicationDynamicViewLoad.Models.TestModel

    "at"Model.Name

    ";ViewBag.HtmlCode = str;return View();} But I am getting output like this: "at"inherits System.Web.Mvc.WebViewPage "at"model WebApplicationDynamicViewLoad.Models.TestModel "at"Model.Name
    – Mahesh Kudikala Apr 10 '19 at 12:39

1 Answers1

0

There are a couple questions with answers already on SO for this. This answer to this similar question has four links to other answers:

Load Razor Views From Database in ASP.NET MVC 5

In addition to that, I would add that you can also accomplish this with RazorLight, which is a 3rd party library. The author offers a specific example of a custom view source using a database:

https://github.com/toddams/RazorLight#custom-source

Bryan Lewis
  • 5,629
  • 4
  • 39
  • 45