Search code examples
asp.net-mvcspark-view-engine

MVC (spark view engine) Whats the difference between x and m?


I came across something strange/weird when coding a spark file. I knew about Html.TextBoxFor, but i noticed my view was rendering it as pure text when i used this:

${Html.TextBoxFor(x => x.Name}}

But when i changed it to this it worked:

${Html.TextBoxFor(m => m.Name)}

the m here probably stands for Model as i've declared the mode like so at the top of the .spark file:

<viewdata model="Test.Models.RegisterViewModel" />

But x or m should be a delegate declaration or something. Could anyone tell me why x wont work in this case? Shouldnt it assume that everything i put in as x or m would be the model I've declared at the top of the page?


Solution

  • Copied from your question:

    ${Html.TextBoxFor(x => x.Name}}
    ${Html.TextBoxFor(m => m.Name)}
    

    In the top one (using x) you have two closing curly braces instead of a parentheses and a brace.

    In the second one (using m), you have the correct closing parentheses and brace. I can imagine that's why Spark rendered it as pure text in the top instance because it didn't recognise a code block there since you were missing a close paren.