Search code examples
c#parsingrazorengine

Replace value inside a word using RazorEngine


For example I have

var model = new MyModel();
model.ClientName = "StackOverFlow";
string result = Razor.Parse("AccountValidation@Model.ClientNameText", model);

This code currently fails which is normal.

I would want my result to be "AccountValidationStackOverFlowText"

Is there some kind of escape character to make this work ? for example

AccountValidation[@Model.ClientName]Text

Solution

  • The syntax for what you want is: text@(yourcodehere)text

    <p>AccountValidation@(Model.ClientName)Text</p>
    

    In your case I'd do:

    string result = "AccountValidation" + model.ClientName + "Text";