.Net Framework 4.5.2 using project properties
Mysql.Data.Entity using NuGet(6.10.8)
Setup Web.config
Fix version of entry System.Web.Mvc.MvcWebRazorHostFactory at views/Web.config
Classes
//Ado
using System;
using System.Data.Entity;
using MySQLEntity.Models;
namespace MySQLEntity.Entity
{
public class MyDb : DbContext
{
public MyDb() : base("ferredb")
//public MyDb() : base(nameOrConnectionString: "ferredb")
{
}
public DbSet
}
}
//Entity
using System;
//Added
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace MySQLEntity.Models
{
[Table("Users")]
public class Usuario
{
[Key]
public string usuario { get; set; }
public string apenom { get; set; }
}
}
Controller Snippet code
public ActionResult Index()
{
MyDb db = new MyDb();
var Model=db.Usuarios.ToList();
return View(Model);
}
View Snippet code
@foreach (var item in Model)
{
<div> @item.usuario @item.apenom </div>
}
Action results
References:
[1] MySQL EntityFramework web.config https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/
[2] Action results
https://www.c-sharpcorner.com/article/different-types-of-action-results-in-asp-net-mvc/
[3] ViewBag better than DataView http://www.tutorialsteacher.com/mvc/viewbag-in-asp.net-mvc
No comments:
Post a Comment