0

I'm new to ASP MVC and I'm completely stuck.

All I want to do is have a control like this:

<td><asp:TextBox ID="txbFirstName" runat="server" Value=""></asp:TextBox></td>

But have it populated by a value from a controller.

This syntax is what I was expecting would work:

<td><asp:TextBox ID="txbFirstName" runat="server" Value="<% Model.FirstName%>"></asp:TextBox></td> 

But obviously it doesn't. I hope from that you can tell what I'm trying to do (populate the value of the text box with a server control) but that won't work. Is this not possible using ASP:Textboxes? Do I need to use HTML boxes instead?

Apparently in ASP 4 MVC the <% %> tags are no longer used and I cannot find a working example anywhere. I thought this would be a simple google but I've been stuck for hours.

Thank you for any help you can provide.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964

1 Answers1

1

Microsoft MVC doesn't use server side controls. You should use HTML Helpers and Model Bindings with Razor view engine (better than ASP.NET view engine).

In the view:

@Html.EditorFor(model => model.Firstname)

A simple Login form:

        @using (Html.BeginForm("LoginAction", "LoginController"))
        {

            @Html.LabelFor(model => model.User, "Your UserName")
            @Html.EditorFor(model => model.User)

            @Html.LabelFor(model => model.Password, "Your Password:")
            @Html.PasswordFor(model => model.Password)

            <button type="submit">Submit</button>
        }

See http://www.asp.net/mvc/overview/getting-started

Gonzalo
  • 2,866
  • 7
  • 27
  • 42
  • Thank you everyone for the responses :) I'm still working on getting it to work but at least I'm pointed in the right direction now. – user3170393 Jan 07 '14 at 20:15