C# replace shortcode with partialview in ASP .NET

Occasional Visitor

I have defined few shortCode in Database. When i am displaying in view, ShortCode not replacing with the PartalView defined in the Dictionary.

In Database i am creating a field Description. There i am storing HTML text along with Few Short code. When i display Description in view. I want the short Code to replace with Partial view. Like we do in WordPress/Joomla. In Database i define ShortCode. I want that sortCode replaced with PartialView.

This is the message i am getting on the screen microsoft.AspNetCore.Mvc.ViewFeatures.Buffers.ViewBuffer

 


@{
var input = "<div>Hello This is Same</div><div>{partv _AllPages}</div><div>Some Content</div><div>{partv _AllPost}</div>";
var replacements = new Dictionary<string, string>
{
{ "{partv _AllPages}", Html.Partial("_AllPages").ToString()},
{ "{partv _AllPost}", Html.Partial("_AllPost").ToString()}
};
var output = replacements.Aggregate(input, (current, replacement) => current.Replace(replacement.Key, replacement.Value));
}
@Html.Raw(HttpUtility.HtmlDecode(output))

 

2 Replies

Hi @shankar2285,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET. Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang

 

@shankar2285 

If you find a solution, you must tell me about it. I'm curious in the answer to the Quackity t-shirt problem.