I have the form that uses 2 models so I include that this way:
@model Equipment.Models.PublicViewModel
where PublicViewModel is
namespace Equipment.Models
{
public class PublicViewModel
{
public Device Devices { get; set; }
public UserCredentials Data { get; set; }
}
}
For example UserCredential class looks like:
namespace Equipment.Models
{
public class UserCredentials
{
[Required]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
}
}
and my form:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true)
<div class="input-group">
@Html.LabelFor(model => model.Data.UserName, new { @class = " input-group-addon" })
@Html.TextBoxFor(model => model.Data.UserName, new { @class = "form-control" })<br />
@Html.ValidationMessageFor(model => model.Data.UserName)
</div>
...
<div class="input-group">
@Html.LabelFor(model => model.Devices.DeviceSerialNumber, new { @class = " input-group-addon" })
@Html.TextBoxFor(model => model.Devices.DeviceSerialNumber, new { @class = "form-control" })<br />
@Html.ValidationMessageFor(model => model.Devices.DeviceSerialNumber)
</div>
...
}
In other form when I use only one model everything works. Can anyone tell me why this isn't working for 2 models?