Usuário com melhor resposta
Problema com expressao lambda

Pergunta
-
Olá sou Iniciante com ASP .NET C# e tenho enfrentando uma dificuldade
Estou fazendo uma pequena aplicação onde são cadastrados alguns dados com helpers, mas fiquei preso num erro de uma expressão lambda
"Uma árvore de expressões não pode conter uma operação dinâmica"
O meu código:
// Classe Pessoa using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace PostGetModelComHelpers.Models { public class Pessoa { public int PessoaId { get; set; } public string Nome { get; set; } public string Twitter { get; set; } } }
// Controller HomeController using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using PostGetModelComHelpers.Models; namespace PostGetModelComHelpers.Controllers { public class HomeController : Controller { public ActionResult Index() { var pessoa = new Pessoa { PessoaId = 1, Nome = "Hugo", Twitter = "nope" }; return View(pessoa); } [HttpPost] public ActionResult Lista(Pessoa pessoa) { return View(pessoa); } } }
// View Lista @model PostGetModelComHelpers.Models.Pessoa @{ ViewBag.Title = "Lista"; } <h2>Lista</h2> <div> <b>@Html.LabelFor(x=>x.PessoaId)</b> </div> <div> @Model.PessoaId </div> <div> <b>@Html.LabelFor(x => x.Nome)</b> </div> <div> @Model.Nome </div> <div> <b>@Html.LabelFor(x => x.Twitter)</b> </div> <div> @Model.Twitter </div> <!-- agora em vez disso <a href="~/" title="Voltar">Voltar</a> será: --> @Html.ActionLink("Voltar","Index","Home")
// View Index.cshtml @{ ViewBag.Title = "Index"; } <h2>Index</h2> <!-- sem helper: form action="/Home/Lista" method="POST">--> <!-- com helper:--> @using (Html.BeginForm("Lista", "Home", FormMethod.Post)) { <fieldset> <legend>Pessoa</legend> <div> @Html.LabelFor(x => x.PessoaId) <div> @Html.LabelFor(x => x.Nome) </div> <div> @Html.EditorFor(x => x.Nome) </div> <div> @Html.LabelFor(x => x.Twitter) </div> <div> @Html.EditorFor(x => x.Twitter) </div> <p><input type="submit" value="Enviar" /></p> </fieldset> }
O erro ocorre justamente no index.cshtml nas partes (x => x.PessoaId) , (x => x.Nome) , (x => x.Twitter)
Se alguem puder me ajudar agradeço
- Movido welington jrModerator quarta-feira, 9 de janeiro de 2019 12:24 forum mais especifico