I want the default record to create a project in MVC5, under repeat password put a selection list ( ComboBox
) where I show the list of the roles that exist in the table AspNetRoles
creates by default the Visual Studio.
I have had problems getting the list of the AspNetRoles
, since I do not know what the context is that uses the Idendity
, and the select
is not created exactly.
I just need to know how to get the list in the controller and how pass it on, the
Insert
I do not need it.
My Controller:
// GET: /Account/Register
[AllowAnonymous]
public ActionResult Register()
{
return View();
}
My View:
@model StyleTest.Models.RegisterViewModel
@{
ViewBag.Title = "Registrarse";
}
<h2>@ViewBag.Title.</h2>
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Cree una cuenta nueva.</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Registrarse" />
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
My connection in the web.config:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=StyleTest;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="StyleTestEntities" connectionString="metadata=res://*/Contexto.StyleTest.csdl|res://*/Contexto.StyleTest.ssdl|res://*/Contexto.StyleTest.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=StyleTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Use MVC5 with Visual Studio 2015.