Don't ask why, but I decided to try to use the porridge that was "just right" in VB while trying to create a site using the new
ASP.NET MVC framework. As I will no doubt forget the syntax to use in about 42 seconds, I'm including it here. Others may find it useful as well.
ActionLinks:
<%=Html.ActionLink(Of ViewEngines.CategoryController) _
(Function(c As ViewEngines.CategoryController) c.Add(), _
"Add Category")%>
Form definition:
<% Using Html.Form(Of ViewEngines.CategoryController) _
(Function(c As ViewEngines.CategoryController) c.Update(ViewData.CategoryID), _
FormMethod.Post)%>
The
Function(c as ViewEngines.CategoryController) c.blah syntax is the equivalent syntax to the shorter, more symbolrific C# syntax:
c => c.Add().
That was still giving me an error. What I found (see below) was that the
trick seems to be to change your methods into functions (instead of the Subs that I was using), and it would work:
Public Function Update(ByVal id As Integer) As Object
Dim c As New Category()
c.LoadByKey(id)
c.LoadFromPost()
c.Save()
RedirectToAction("List")
Return Nothing
End Function
Now someone can please tell me I'm wrong, and there is a simpler solution. Barring that, I think I might stick with using the "
less correct" versions of the calls (or, more likely, using C# for all my MVC sites)
(Special thanks to Chuwanga on the asp.net forums for the
original solution. I wouldn't have figured out that last step)
Print | posted on Thursday, April 17, 2008 1:46 PM