Asp.net Mvc Razor For Loop Syntax
Apr 5, 2012Trying to create VB.net equivalent for following code and I get error
<ul>
@for (int i=0; i < ViewBag.NumTimes; i++) {
<li>@ViewBag.Message</li>
}
</ul>
Trying to create VB.net equivalent for following code and I get error
<ul>
@for (int i=0; i < ViewBag.NumTimes; i++) {
<li>@ViewBag.Message</li>
}
</ul>
MVC 3 is great but in some cases I am having trouble translating the Razor syntax. Anyone know of a good VB.Net Razor reference?
View 1 RepliesIn the MVC 3 book by Steven Sanderson on p185 at the bottom, the following expression is used to render the paging links.
@Html.PageLinks(Model.Paginginfo, x=> Url.Action("List", new {page = x}))
What is the VB.NET equivalent? I am stuck on the x url lambda bit.
I am new to Razor view syntax and as most of the examples are in C# in coverting the below Razor syntax to vb.net
<div>
@using (Html.BeginForm())
{
[code].....
This should not be as hard as it seems to be, but I can't for the life of me create a table in VB using Razor syntax. The following does not work (despite what some examples would lead me to believe):[code]
View 2 RepliesI am working on MVC3, i have a situation where i want to do something like this:
<Div>
@Code
Dim i = 1
[Code]....
but razor is throwing wrong syntax error message. how to do this properly in side razor code.
Using MVC3 and Razor View engine, I created a VB.NET web application in VS 2010. This creates the default Account and Home Controller along with corresponding Action Views.Now if I open any vbhtml file I get the following error message in the Error List window.
Error 50 Syntax error. C:****MVC3AppVBViewsAccountLogOn.vbhtml MVC3AppVB
(See screenshot here http://www.flickr.com/photos/7672540@N07/5469248676/)
[code].....
VB.Net 2002 - Framework 1.0..I have below code and getting syntax error in For Loop at "To" [code]Error is at To in For loop.
View 3 RepliesI have below code and getting syntax error in For Loop at "To"[code].....Error is at To in For loop.
View 1 RepliesI'm following the ASP.NET MVC Tutorial and having started in VB.NET I'm having trouble converting the following razor code:
[code]...
on both the <li> tags. I understand I need to use line continuation but can't figure out where. I'd be greatful if you can point out the problem.
how do I add this htmlAttribute on MVC 3 Razor view?
New With {.watermark = "sometext", .title = "sometext"}
I tried the C# way but it's not working (@watermark) but it's not working.
UPDATE here is the current usage I am trying but it's not working.
@Html.EditorFor(Function(model) model.FirstName, New With {.maxlength = "50"})
This isn't working either
@Html.EditorFor(Function(model) model.FirstName, New Object() {"maxlength=50"})
How do I do this in Razor (VB.NET):
[Code]....
I have a razor.vbhtml view and would like to use string resources normally accessible via My.Resources. Seems like I can only get to My.Computer, My.Log and couple other namespaces from the view, but not My.Resources. I've tried changing access modifier to public and adding Imports, neither worked.
View 1 RepliesIs not the @Model MyModelClass notation not supported in VB Razor Views? It's not working for me. What is the construct for it?
View 1 RepliesI have this C# code in a Razor view:
@(Html.CheckBoxFor<RazorSamplesWeb.Models.SamplesModel>(i => i.IsActive))
I tried translating it to this:
@Code Html.CheckBoxFor(Of RazorSamplesWeb.Models.SamplesModel)(Function(i) i.IsActive)End Code
But it's complaining.
I just downloaded the MVC 3.0 RC and I'm excited to start using it, especially the Razor view engine. However, due to a few stick in the mud type people here, we are stuck using VB.NET instead of C#.When I started trying it out, I noticed some quirks. If you are creating a Razor view using CSHTML, you can write code like this:
@foreach(string genreName in Model.Genres)
{
<li>@genreName</li>
}
Razor will automatically detect that the <li> text is an HTML tag and will switch out of "code mode". With a VB.NET VBHTML file, this doesn't seem to be working. It's making me put the @: keyword in front of each line like this:
@For Each genreName As String In Model.Genres
@:<li>@genreName</li>
Next
If I don't have it there, I get a runtime error. Also, the <text></text> tags don't seem to work.
I've the following code for a DropDownListFor and is working ok
@Html.DropDownListFor(Function(model) model.Habilitacoes, New SelectList(ViewBag.Habilitacoes, "KeyHL", "DescricaoHL"), New With {.class = "FillHSpace"})
[code].....
I am getting extra whitespace characters rendered in my horizontal list of anchor tags below. This is causing a major CSS styling issue for me. I know this question has been addressed as far as a C# workaround is concerned (asp.net mvc razor extra space), but can anyone help me with a VB workaround? I don't have the advantage of curly braces to eliminate all whitespace in a single-line If condition.
I have managed to work around it for now by writing an HtmlHelper extension method, but this dynamic code is only used in one place (the master layout page). It seems to me that this should really be done in the .vbhtml page. Here is the erroneous code, along with commented-out attempts at workarounds. The goal is to create a horizontal list of "sibling" pages based on a site map, with slightly different styles for the current page's link and the link just before it. [Code]
Check out this code sample from Scott Guthrie's blog: [URL]...Notice item is a reference to the currently executing item in C#, what is the equivalent keyword in VB.NET?
EDIT: I should add here is my actual implementation of a method accepting a template:
Public Function RenderInlineTemplate(ByVal template As Func(Of RazorSamplesWeb.Models.SamplesModel, Object)) As IHtmlString Return New HtmlString("<div style='display:inline;'>" + template(Model) + "</div>")
End Function And I get this error: Compiler Error Message: BC30201: Expression expected.
[Code]...
How do I modify or create my own Html.ActionLink helper to accept and handle the first parameter (linkText) passed in as an empty string / nothing?Details: I currently have a strongly typed view that's passed a model which contains search results. My view loops through each item in the model and attempts to display a link to a contact with the following code:
@Html.ActionLink(currentItem.ContactName, "contact", "details", New With { .id = currentItem.ContactID }, Nothing)
Normally this would work just fine, but not every item in my search result has a ContactName. The Html.ActionLink helper errors when this first parameter is empty. In case it helps, here's the model property for ContactName (which is generated from a template due to Database First, so I don't believe it can be modified):
Public Property ContactName As String
I'd like to have a helper function that simply returns nothing if the ContactName is an empty string / nothing.I'm guessing I need to extend this helper, and I've struggled to find any good, up-to-date resources in VB.net for extending helper functions. Other approaches are more than welcome if they're considered best practice. I'm working in VB.net, MVC3, and Razor in the ASP.net 4.0 framework.
How do I reference a Namespace in .NET MVC3 with the Razor view engine?
I understand this can be done in C#:
@using Namespace;
However in VB this doesn't seem to work:
@Imports Namespace
(i'm talking about inside a .vbhtml file)
Makes the following statement about the code below:
**"The computer evaluates the loop condition in the Do...Loop statment to determine whether the loop instructions should be processed. In this case, the inputsales <> String.Empty condition compares the contenst of the input sales variable to the String.Empty value. As you know the String.Empty value represents a zero length, or empty, string if the inputsales variable is empty, the loop condition evaluates to True and the computer process the loop instructions. *If on the other hand the inputsales variable is not empty, the loop condition evaluates to false and the computer skips over the loop instructions.
Based on the code I think it is the opposite: ...that while the inputsales value is not empty it should evaluate to true and process the loop and if it is empty it should evaluate to false and skip the loop?
See below.
Option Explicit On
Option Strict On
Imports System.Globalization
[CODE]...
I'm creating a new website in Visual Studio 2010 Ultimate / vb and I want to add things to it, to jazz it up. So I'm adding new projects from the VS online templates. It seems there are many more projects in c# than vb. I'm trying to figure out if it's okay to add a c# and razor project to a vb website, because if not, I'll start the website in c#.
Will mixing languages between projects within your website present issues in the future when it comes time to build and publish? Or is it recommended I begin the website in c# (since there are more projects within VS) and keep the languages the same throughout the website?
In other languages (PHP/Python), I am used to creating a class which represents a given HTML page layout. These classes can have an unlimited number of attributes and dynamic features, such as Navigation (multi level), error messages, info messages, footer text, etc... Most of these items have defaults, but may be overridden on a per-page level. For example:
[Code]....
My question is: how do I implement similar functionality into ASP.Net MVC 3 Razor (VB)? So far, I have been able to see how you can use ViewData to pass various bits of data to a view. Also, I have been working with strongly typed views. Frankly, I'm not sure who's job it is to have this logic, the controller or the view (or is there a model that should be in there somewhere). Here is a summary of what I am shooting for:
A single place to initialize the default values for the layout (like the first layer of navigation, etc...) Strongly typed attributes, such as Public Readonly Property Nav1 as List(of NavElement) And a single place to render these layout elements (I assume _Layout.vbhtml) forgive the here-and-there of this post... I'm trying to figure out the "right way" it's done on a platform that is both new (Razor) and new to me (ASP.Net MVC).
MVC 3, VB.NET. I have a form in my app that gets basic information from the user and then allows them to upload a resume. I am accomplishing this right now by using a redirect to a different form that's only purpose is to select the file for uploading and then submit it.. Sloppy in my opinion.. I have tried to do it from the same form but the file is being lost on submit.. While I am not certain of it I believe it is because I am not using the correct syntax in the form to handle the file.[code]
View 1 RepliesI have a funtion that returns a generated PDF file but the problem is it shows it in the current browser window... I need for it to open in a new window. I dont see how I can pass it into a view for displaying where I could simply use target: _blank.
Function showUserPDF(ByVal pdfName As String) As ActionResult
Dim _fileName As String = pdfName
Dim _path As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) +
[Code].....
I'm trying to create a Grid in MVC3 with razor and VB.NET. The normal Grid works fine, sorts and paginates fine, but when trying to make the Ajax binding, I get an error 500 - internal server error when I try to go to the next page.
[Code]...
I am having an issue trying to figure this out. I am writing a script editor that uses tabs (a tab control) and I want to implement syntax highlighting. My issue is that every sample I can find on syntax highlighting uses
Private Sub RichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
I want to use the Linkshare helper in the Microsoft.Web.Helpers dll. I added the reference to my project but if attempt to use it in the vbhtml file Visual studio underlines it with a blue squiggly and tells me it is inaccessible blah blah. I even added references to those webmatrix dlls as described here[url]...
View 2 RepliesThis is driving me round the bend. I'm a long time VB.NET forms developer, quite new to ASP.NET and completely new to MVC. I'm creating vbhtml pages that use the VB.NET razor syntax, and I seem to be constantly fighting against the UI which is trying to indent my code incorrectly. Take the following example, based on the template page for a new Razor view:
@Code
Layout = Nothing
End Code
[code].....