Microsoft Virtual Academy Cursos técnicos gratuitos en línea Tome un curso gratuito en línea. http://www.microsoftvirtualacademy.com
Microsoft Virtual Academy Aprendiendo a Programar
Validando
Validando
Validación en el servidor
Validación en el servidor - Modelo using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MvcSimpleModelBinding.Models public class Person public int Id get; set; public string Name get; set; public int Age get; set; public string Street get; set; public string City get; set; public string State get; set; public int Zipcode get; set;
Validación en el servidor - Controller public class PersonController : Controller static List<Person> people = new List<Person>(); public ActionResult Index() return View(people); public ActionResult Details(Person person) return View(person);... public ActionResult Create() return View(); [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Person person) if (!ModelState.IsValid) return View("Create", person); people.add(person); return RedirectToAction("Index");
Validación en el servidor Vista Index @using MvcSimpleModelBinding.Models; @ ViewBag.Title = "Index"; <h2>listado</h2> <table> <tr> <th></th> <th>id</th> <th>nombre</th> </tr> @foreach (Person person in Model) <tr> <td>@html.actionlink("ver Detalle", "Details", person)</td> <td>@html.encode(person.id)</td> <td>@html.encode(person.name)</td> </tr> </table> <p>@html.actionlink("crear Nueva Persona", "Create")</p>
Validación en el servidor Vista Create @using MvcSimpleModelBinding.Models; @ ViewBag.Title = "Create"; <h2>crear</h2> @using (Html.BeginForm()) @Html.ValidationSummary() <fieldset> <legend>campos</legend> <p><label for="id">id:</label>@html.textbox("id") @Html.ValidationMessage("Id", "*") </p> <p><label for="name">nombre:</label>@html.textbox("name") @Html.ValidationMessage("Name", "*") </p> <p><label for="age">edad:</label>@html.textbox("age") @Html.ValidationMessage("Age", "*") </p> <p><label for="street">dirección:</label>@html.textbox("street") @Html.ValidationMessage("Street", "*") </p> <p><label for="city">ciudad:</label>@html.textbox("city") @Html.ValidationMessage("City", "*") </p> <p><label for="state">provincia:</label>@html.textbox("state") @Html.ValidationMessage("State", "*") </p> <p><label for="zipcode">c.postal:</label>@html.textbox("zipcode") @Html.ValidationMessage("Zipcode", "*") </p> <p><input type="submit" value="create" /> </p> </fieldset> <div>@html.actionlink("volver al Listado", "Index")</div>
Validación en el servidor Vista Details @using MvcSimpleModelBinding.Models; @ ViewBag.Title = "Details"; <h2>detalle</h2> <fieldset> <legend>campos</legend> <p>id: @Html.Encode(Model.Id) </p> <p>nombre: @Html.Encode(Model.Name) </p> <p>edad: @Html.Encode(Model.Age) </p> <p>dirección: @Html.Encode(Model.Street) </p> <p>ciudad: @Html.Encode(Model.City) </p> <p>provincia: @Html.Encode(Model.State) </p> <p>c. Postal: @Html.Encode(Model.Zipcode) </p> </fieldset> <p>@html.actionlink("volver al Listado", "Index") </p> Mas información y tutoriales en: http://www.asp.net/mvc/tutorials/mvc-5/ introduction/getting-started
Validación en el servidor - Contras
Validación en el cliente - JavaScript function validateform() var x=document.forms["myform"]["fname"].value; if (x==null x=="") alert("first name must be filled out"); return false; return validateform()
Validación en el cliente - JavaScript
Validación en el cliente http://jqueryvalidation.org/
Enviando correos
Enviando correos - Modelo public class CorreoModel public string From get; set; public string To get; set; public string Subject get; set; public string Body get; set; Luego en la carpeta Controller crearemos un nuevo controlador llamado EnviarCorreoController
Enviando correos - Controlador using System; using System.Collections.Generic; using System.Linq; using System.Net.Mail; using System.Web; using System.Web.Mvc; namespace EnviarCorreo.Controllers public class EnviarCorreoController : Controller // // GET: /EnviarCorreo/ public ActionResult Index() return View(); [HttpPost] public ActionResult Index(EnviarCorreo.Models.CorreoModel _objmodelmail) if (ModelState.IsValid) MailMessage mail = new MailMessage(); mail.to.add(_objmodelmail.to); mail.from = new MailAddress(_objModelMail.From); mail.subject = _objmodelmail.subject; string Body = _objmodelmail.body;
Enviando correos - Controlador mail.body = Body; mail.isbodyhtml = true; SmtpClient smtp = new SmtpClient(); smtp.host = "smtp.outlook.com"; smtp.port = 587; smtp.usedefaultcredentials = false; smtp.credentials = new System.Net.NetworkCredential ("username", "password");// Enter seders User name and password smtp.enablessl = true; smtp.send(mail); return View("Index", _objmodelmail); else return View(); Y finalmente, en la carpeta de vistas, tendremos Index.cshtml
Enviando correos - Vista @model EnviarCorreo.Models.CorreoModel @ ViewBag.Title = "Index"; <h2>index</h2> <fieldset> <legend>send Email</legend> @using (Html.BeginForm()) @Html.ValidationSummary() <p>from: </p> <p>@html.textboxfor(m=>m.from)</p> <p>to: </p> <p>@html.textboxfor(m=>m.to)</p> <p>subject: </p> <p>@html.textboxfor(m=>m.subject)</p> <p>body: </p> <p>@html.textareafor(m=>m.body)</p> <input type ="submit" value ="Send" /> </fieldset>
Explicando nuestro ejemplo En el controlador tenemos un código que dice: ViewResult Index (EnviarCorreo.Models.CorreoModel _objmodelmail) En este método, tenemos un dato que tiene la forma de nuestro CorreoModel. Luego creamos un dato MailMessage y le completamos toda la información que necesita: To From Cc Bcc Subject Body
Explicando nuestro ejemplo
Interfaces avanzadas
Interfaces avanzadas https://jqueryui.com/
Interfaces avanzadas http://www.microsoft.com/en-us/default.aspx http://www.microsoft.com/surface/en-us http://windows.microsoft.com/en-us/windows/home http://whois.wildlife.la/ http://www.fk-agency.com/ http://www.sweez.com.br/ http://www.l2systems.com http://www.tridentpp.com/ http://tomerlerner.com http://flashvhtml.com/ http://nasaprospect.com/
Persistiendo
Persistiendo
Persistiendo
2016 Microsoft Corporation. All rights reserved. The text in this document is available under the Creative Commons Attribution 3.0 License, additional terms may apply. All other content contained in this document (including, without limitation, trademarks, logos, images, etc.) are not included within the Creative Commons license grant. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. This document is provided "as-is." Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. Some examples are for illustration only and are fictitious. No real association is intended or inferred. Microsoft makes no warranties, express or implied, with respect to the information provided here.