Using C# MVC4
My View:
@using Universe.Models
@model UserModel
@section css {
<link href="@Url.Content("~/Content/assets/charcreation.css")" rel="stylesheet"/>}
@using (Html.BeginForm("AddUser","Home", FormMethod.Post))
{
<div class="row-fluid">
<table id="tblBio">
<tr>
<td class="span3">
<span class="labeltext">Alias:</span>
</td>
<td class="span5">
@Html.TextBox(Model.Alias)
</td>
<td class="span4">
<span class="ui-state-highlight hidden"></span>
</td>
</tr>
My Model:
public class UserModel
{
public int Id { get; set; }
public string Alias { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool IsExternal { get; set; }
public UserModel()
{
}
public UserModel(User user)
{
if (user == null) return;
Alias = user.Alias;
}
}
But, I keep getting the error:
When I try to debug it, it doesn't even go into the Html.TextBox
method or into my model.
Without seeing your controller action, my guess would be that your model is null.
In your controller, make sure you are passing an instance of the model to your view. For example:
return View(new UserModel());
Instead of:
return View();
You have to pass your Model
in your Controller
Action when return the specific View
return View(new Model());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With