Question

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?

Was it helpful?

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.

OTHER TIPS

There is no difference between the two . The variable is like a counter used in for ( a local variable that defines the common action taken upon all objects within the lambda expression.

The reason why that worked is probably the fact that you had an error in your previous code syntax, or you forgot to build

my 2 cents
Disclaimer: I didn;t see the spark tag ... This answer is totally dedicated to the MVC aspect of the issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top