Wednesday, December 2, 2009

Finally, answers to how Controllers know about variables on a View

So, it's taken a while, but I've finally figured out how views variables and controllers work, with AJAX.

Ok,

For a controller method to see the value of a tag on a view, you must create a "<[percent]=HTML" tag. You can't just create a regular html tag, you must use the MVC ASP.NET helper.

It Must be in the AJAX form that you are submitting. It cannot be outside the form or the method will not see it.

They method sees the NAME you give the helper tag, NOT the id. So you can have multiple tags with the same name. This is helpful when you want to ajax a lot of functionality but need to keep the same tags but change the values, like knowing which view the user is currently on.

On Complete for AJAX happens when the form is finished submitting, NOT when it finishes loading.

Dec 7, 2009 - It, also, appears that initializing a Html.Hidden(...) field with a @value=".." will not be sent to the server. In other words, if you give @value="..." in the html attributes, the "..." will not be seen on the server. I've found that you must change the value in javascript.

Hope this helps.

No comments:

Post a Comment