Monday, May 5, 2008

Tonight's MVC progress

Yesterday's post didn't go so well. The code and HTML isn't rendering correctly. Lets try screenshots.

I have the edit functionality working. I ran into one glitch along the way. The edit page is a form. I set the action attribute using Url.ActionLink, but it didn't do anything. It kept posting back to the view page. "View Source" revealed that there are 2 form tags: 1 for the master page, plus the one I added. I removed the one from the master page, and it started working. (If I wasn't able to remove the parent form tag, what would I have to do? Maybe change the parent's action instead?)



Here's the main page. Its using the master page and css provided by the template. Its nicer than anything I could've done, so I'll keep it.





The MVC links are:
Clan Admin - http://localhost:1653/ClanAdmin/Index
Home - http://localhost:1653/Home/Index
About - http://localhost:1653/Home/About
Login - http://localhost:1653/Home/Login

When you click Clan Admin, you get the really ugly list of people.




The Edit page url is http://localhost:1653/ClanAdmin/EditPerson/3. The last segment is the people id.


When you click save, it submits to /ClanAdmin/UpdatePerson/3.


Here's the UpdatePerson action.

BindingHelperExtensions.UpdateFrom is neat. It looks at the posted form and maps the element names to the object property names. So, name your controls the same as the properties, and you can do the update in one swoop. It also provides measures to prevent certain properties form being updated, but I'm not using that here.

Yesterday I mentioned that I would need to create a partial class to add more specific functionality to ClanContextData. I was going to add a class to APP_CODE, but that doesn't exist in ASP.NET. Its been removed from the ADD ASP.NET FOLDER menu. So, I put it in the controller folder, which I now think is the correct place. (The REAL right place would be a separate assembly that contains all of the business logic. But, I don't have that piece. It's all in Controllers).


No comments: