[RESOLVED]Issue with Razor and VB.net Supplying a default value

I have been able to do this with C# but with VB.net in the view I am having issues with syntax.

C# works great:
@Html.TextBoxFor(model => model.Address, new { @class="BTCaddress", @Value="" + ViewBag.Address + "" })

Not sure how to format in VB.net? I also have issues getting it to work with EditorFor:

Regular scaffolded code:
@Html.EditorFor(Function(model) model.Company, New With {.htmlAttributes = New With {.class = "form-control"}})

What I have tried:
@Html.EditorFor(Function(model) model.Company, New With {.htmlAttributes = New With {.class = "form-control", @Value="" & @ViewBag.Company & "" }})

Should I be using TextboxFor  in VB.net for this and how would I format it?

Hi,

Based on my test in the MVC 5 project, I found that we can’t set the default value by specify the data to the value.

For the Html.XXFor method, the default value should be based on the field value of Model. So, you need to create an instance with the default value and return to the view. You also could use
Html.TextBox method.

belcherman

@Html.TextBoxFor(model => model.Address, new { @class="BTCaddress", @Value="" + ViewBag.Address + "" })

Not sure how to format in VB.net? I also have issues getting it to work with EditorFor:

The VB code should be:

@Html.TextBoxFor(Function(m) m.Address, New With {.class = "BTCaddress",.value=ViewBag.Address})

Best Regards

Starain Chen

Leave a Reply