Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WebPages
- {
- [Key]
- public int WebPagesId { get; set; }
- public int ClientsId { get; set; }
- [ForeignKey("ClientsId")]
- public virtual Clients Clients { get; set;}
- public String ClientsName { get; set; }
- public String DomainName { get; set; }
- public String DomainEmails { get; set; }
- public String DomainUsers { get; set; }
- public String DomainPasswords { get; set; }
- }
- }
- public class WebPagesViewModel
- {
- public String DomainName { get; set; }
- public String DomainEmails { get; set; }
- public String DomainUsers { get; set; }
- public String DomainPasswords { get; set; }
- public int SelectedClient { get; set; }
- public IEnumerable<SelectListItem> Clients { get; set; }
- }
- public ActionResult Create(WebPages model)
- {
- var vm = new WebPagesViewModel
- {
- Clients = new SelectList(db.ClientsList, "ClientsId", "ClientsName"),
- };
- return View(vm);
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> Create([Bind(Include = "DomainName,DomainEmails,DomainUsers,DomainPasswords,ClientsName,SelectedClient")] WebPagesViewModel model)
- {
- model.Clients = new SelectList(db.ClientsList, "ClientsId", "ClientsName");
- try
- {
- if (ModelState.IsValid)
- {
- model.WebPagesCreate();
- return RedirectToAction("Index", "WebPages");
- }
- }
- catch (Exception)
- {
- //Exception code
- }
- return View(model);
- }
- @model IncursusAccounting.Models.ViewModels.WebPagesViewModel
- @{
- ViewBag.Title = "Create";
- }
- <h2>Create</h2>
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>WebPages</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- <div class="col-md-10">
- @Html.DropDownListFor(m => m.SelectedClient, Model.Clients, "-Selecciona una opcion-", new { @class = "form-control" })
- @Html.ValidationMessageFor(m => m.SelectedClient)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.DomainName, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.DomainName, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.DomainName, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.DomainEmails, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.DomainEmails, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.DomainEmails, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.DomainUsers, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.DomainUsers, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.DomainUsers, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.DomainPasswords, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.DomainPasswords, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.DomainPasswords, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Create" class="btn btn-default" />
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- public class DomainUser {
- public String Email { get; set; }
- public String User { get; set; }
- public String Password { get; set; }
- }
- public ActionResult Index()
- {
- var initialData = new[] {
- new DomainUser { Email = "email@example.org", User = "ExampleUser", Password="ExamplePassword" }
- };
- return View(initialData);
- }
- <h2>Domain Users</h2>
- <% using(Html.BeginForm()) { %>
- <div id="domainUserRows">
- <% foreach (var item in Model)
- Html.RenderPartial("DomainUser", item);
- %>
- </div>
- <input type="submit" value="Finished" />
- <% } %>
- <div class="domainUserRow">
- <% using(Html.BeginCollectionItem("DomainUser")) { %>
- Email: <%= Html.TextBoxFor(x => x.Email) %>
- User: <%= Html.TextBoxFor(x => x.User) %>
- Password: <%= Html.TextBoxFor(x => x.Password) %>
- <% } %>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement