views:

107

answers:

2

Hi,

I'm working through the MVC Music Store in Visual Basic (mvcmusicstore.codeplex.com), trying to convert things as I go. I'm heving trouble with some of the lambda expressions in the Views, however. Specifically, on page 53 when the Album editor template is used, I am not seeing my editor template when I use the following code:

Original: <%: Html.EditorFor(model => model.Album,
new { Artists = Model.Artists, Genres = Model.Genres}) %>

My VB: <%: Html.EditorFor(Function(model) model.Album,
New With { .Artists = Model.Artists, .Genres = Model.Genres}) %>

But the page doesn't show the template at all. I can't find too many useful resources on VB Lambdas to tell whether I am doing this right or not!

+1  A: 

Hi Pete,

i'm trying to rewrite the MVC MusicStore in VB too. Which is not always that simple because the lack of resources. Nevertheless, your code for the Html.EditorFor did the trick and the editor template is shown.

Did you see any errors when trying to access the view?

If you like I can send you my vb project of the MVC MusicStore.

Just let me know.

Rob
Hi, sorry, I forgot I'd left this question on here!Turns out there was a mistake a couple of pages previously - once it was compared with someone else's, the problem turned up and it worked just fine.Thanks for the offer though!
pete the pagan-gerbil
No problem. Can you help me with rewriting to code below. I can't figure out what it should be in VB. Do you know any good vb MVC 2 resources?<%: Html.DropDownList("ArtistId", new SelectList(ViewData["Artists"] as IEnumerable, "ArtistId", "Name", Model.ArtistId))%>
Rob
Sure - in VB, you can't use 'something as somethingelse', you need to use `CType` - for example: `<%: Html.DropDownList("ArtistId", New SelectList(CType(ViewData("Artists"), IEnumerable), "ArtistId", "Name", Model.ArtistId))%>`I'm afraid I don't know any good resources - you'll just need to be able to read C# and work out the conversions. Lambdas can be the hardest part of that.
pete the pagan-gerbil
Thanks a lot, that does the trick!
Rob
A: 

I have been converting the entire application from C# into VB and have this portion coded, will post the code for you when back to my desk.

Matt B
Don't hold your breath ;)
FerretallicA