Olá à todos!
eu estou começando agora no .NET com C# e baixei o Microsoft Visual Web Developer 2010 Express. Seguindo as dicas do site
www.macoratti.net no tópico:
http://www.macoratti.net/10/08/asp_mvc3.htm
Consegui inserir dados, visualizar e editar, mas qdo vou deletar, aparece a seguinte mensagem na página Delete.aspx qdo vou depurar, vejam:
Use the "new" keyword to create an object instance
exatamente nessa linha: <div class="display-field"><%: Model.CategoryID %></div>
Fiz corretamente o que o manual ensinou, mas pq não consigo deletar? Estou usando a database Northwind e a tabela Category como modelo. Veja abaixo o meu código:
.......
public ActionResult Delete(int id)
{
var deletar = (from cat in _eth.Categories where cat.CategoryID == id select cat).First();
return View(deletar);
}
//
// POST: /Category/Delete/5
[HttpPost]
public ActionResult Delete(Category pCategory)
{
try
{
// TODO: Add delete logic here
var deletar = (from cat in _eth.Categories where cat.CategoryID == pCategory.CategoryID select cat).First();
_eth.DeleteObject(deletar);
_eth.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
...............
Obrigado!
Marcos Tavares