Tell me why I get such an error when using the db.Test.Add (view) method; Error: CS1503 Argument 1: cannot convert from 'DC.Models.View' to 'DC.Models.SaveComments.Test'. I try to write data to the database, code:
My Controller:
namespace DC.Controllers
{
public class CommentController : Controller
{
public ActionResult SaveRecord(View model)
{
try
{
DataComment db = new DataComment();
View view = new View();
view.Id = model.Id;
view.Name = model.Name;
db.Test.Add(view);
db.SaveChanges();
}
catch (Exception ex)
{
throw ex;
}
return RedirectToAction("Index");
}
}
}
Models:
namespace DC.Models.SaveComments
{
public class DataComment : DbContext
{
public DataComment()
: base ("CC")
{ }
public DbSet<Test> Test { get; set; }
}
}
namespace DC.Models.SaveComments
{
public class Test
{
public int Id { get; set; }
public string Name { get; set; }
}
}
namespace DC.Models
{
public class View
{
public int Id { get; set; }
public string Name { get; set; }
}
}
And in html-page:
<body>
@using (Html.BeginForm("SaveRecord", "Comment", FormMethod.Post))
{
<p>Id @Html.TextBoxFor(model => model.Id)</p>
<p>Name @Html.TextBoxFor(model => model.Name)</p>
<input type="submit" value="Submit" class="btn-block btn-primary" />
}
</body>