Replace shortcode with partialview in ASP .NET

shankar123

New member
Joined
Aug 10, 2022
Messages
2
Programming Experience
1-3
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

C#:
@{
    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))
 
Last edited by a moderator:
Temporarily, replace line 8 with:
var output = input;

Do you get the same results? If so, next change the var on line 2 to string. If that works, then leave the string on line 2 and restore your previous line 8.
 
Temporarily, replace line 8 with:
var output = input;

Do you get the same results? If so, next change the var on line 2 to string. If that works, then leave the string on line 2 and restore your previous line 8.
Temporarily, replace line 8 with:
var output = input; ==> No error. It displays the same as in line 2. Shortcode is not replacing with the PartialView content.

var on line 2 to string ==> error

both are not working.
 
Back
Top Bottom