使用umbraco mvc 5在数据库中插入数据

时间:2018-05-16 15:34:51

标签: c# asp.net-mvc-4 umbraco

我正在尝试将输入到我的表单上的数据存储到我的数据库表中,但它根本不起作用,这里是模型,控制器是有人想看一看,使用mvc 5和umbraco。

[TableName("staffOnGoingTraining")]  
[PrimaryKey("id")]  
public class CreateEmployeeViewModel    
{
    [HiddenInput(DisplayValue = false)]  
    public int id { get; set; }

    [Required]
    [Display(Name = "Training Name")]
    public string TrainingName { get; set; }
    [Required]
    [Display(Name = "Expected Cost")]
    public string TrainingCost { get; set; }
    [Display(Name = "Start Date")]
    public DateTime TrainingStartDate { get; set; }
    [Display(Name = "Expected Completion Date")]
    [UIHint("NullableDateTime")]
    public DateTime TrainingExpires { get; set; }
}

public class CreateEmployeeViewController : SurfaceController
{

    [HttpPost]
    public ActionResult AddEmployee(CreateEmployeeViewModel viewModel)
    {

        if (Utils.staffDetail.accessLevel > accessLevel.admin)
        {
            return Content("You are not authorized to edit this information");
        }

        if (ModelState.IsValid)
        {
            var db = ApplicationContext.DatabaseContext.Database;
            var sql = new Umbraco.Core.Persistence.Sql();
            db.Insert(viewModel);
            return PartialView("_Create", viewModel);
        }

        return Content("Thank you, your changes have been saved");

    }
}

0 个答案:

没有答案