Customer.cs
Código:
CustomerController.csusing System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Formulario2.Models { public class Customer { public string Code { get; set; } public string Name { get; set; } public int Amount { get; set; } } }
Código:
Vista FillCustomer.cshtmlusing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Formulario2.Models; namespace Formulario2.Controllers { public class CustomerController : Controller { // GET: Customer public ViewResult DisplayCustomer(CustomerController objCustomer) { return View(objCustomer); } public ActionResult FillCustomer() { return View("FillCustomer"); } } }
Código:
DisplayCustomer.cshtml@model Formulario2.Models.Customer @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>FillCustomer</title> </head> <body> <div> @using (Html.BeginForm("DisplayCustomer", "Customer", FormMethod.Post)) { <p> @Html.LabelFor(model=>model.Code,"Código") @Html.EditorFor(model => model.Code) </p> <p> @Html.LabelFor(model => model.Name, "Nombre") @Html.EditorFor(model => model.Name) </p> <p> @Html.LabelFor(model => model.Amount, "Cantidad") @Html.EditorFor(model => model.Amount) </p> <input type="submit" value="Enviar" /> } </div> </body> </html>
Código:
Cuando ejecuto la aplicación me salta una excepcion en la línea 15 de DisplayCustomer.cshtml@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>DisplayCustomer</title> </head> <body> <div> El codigo del cliente es @Model.Code<br /> El codigo del cliente es @Model.Name<br /> @if (Model.Amount > 100) { <p>Este es el cliente privilegiado</p> } else { <p>Este es el cliente normal</p> } </div> </body> </html>
Código:
que puede ser? El código de usuario no controló Microsoft.CSharp.RuntimeBinder.RuntimeBinderException HResult=-2146233088 Message='Formulario2.Controllers.CustomerController' no contiene una definición para 'Code'. Source=Anonymously Hosted DynamicMethods Assembly StackTrace: en CallSite.Target(Closure , CallSite , Object ) en System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) en ASP._Page_Views_Customer_DisplayCustomer_cshtml.Execute() en C:\Users\Usuario\Documents\Visual Studio 2015\Projects\practicando\ASP mvc\Formulario2\Views\Customer\DisplayCustomer.cshtml:línea 15 en System.Web.WebPages.WebPageBase.ExecutePageHierarchy() en System.Web.Mvc.WebViewPage.ExecutePageHierarchy() en System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) en System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) en System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) en System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) en System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) en System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) en System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) InnerException: