小编 ci*_*ess的帖子

首次迁移时访问 Microsoft.Extensions.Hosting 服务时出错

我不明白有什么问题。我试图用一个非常简单的模型在 .net core mvc 中制作一个简单的 crud,该模型几乎没有字段。

这些是我的模型:

    public class Employee
    {
        [Key] public int EmployeeId { get; set; }

        [Required] public string FistName { get; set; }

        [Required] public string LastName { get; set; }

        public int PositionId { get; set; }
        public virtual Position Position { get; set; }

    }
public class Position
    {
        [Key]
        public int PositionId { get; set; }
        public string PositionName { get; set; }
        public ICollection<Employee> Employees { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

然后我制作了应用程序上下文:

public …
Run Code Online (Sandbox Code Playgroud)

.net c# migration entity-framework crud

17
推荐指数
4
解决办法
2万
查看次数

如何通过ajax打开弹出对话框窗口并保存数据.net core mvc

我是 .NET 新手,我想打开一个模式弹出窗口,然后将此数据保存到数据库而不重新加载页面。

首先,用户需要单击一个按钮。Modal是通过ajax加载的。用户填写表格,然后内容经过验证并发布到数据库中。

这是按钮的代码:

<button class="btn btn-primary" asp-controller="Positions" asp-action="Create" 
        data-toggle="ajax-modal" data-target="#add-contact">Add new Positions</button>
Run Code Online (Sandbox Code Playgroud)

这是控制器:

// GET: Positions/Create
public IActionResult Create()
{
    return View();
}

// POST: Positions/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("PositionId,PositionName")] Position position)
{
    if (ModelState.IsValid)
    {
        _context.Add(position);
        await _context.SaveChangesAsync();
        return RedirectToAction(nameof(Index));
    }
    return View(position);
}
Run Code Online (Sandbox Code Playgroud)

这是模型(很简单)

public class Position
{
    [Key]
    public int PositionId { get; set; }
    public string PositionName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我的观点的代码:

@model Models.Position

@{
    ViewData["Title"] = "Create";
}

<h3>Create Position</h3> …
Run Code Online (Sandbox Code Playgroud)

.net javascript ajax jquery asp.net-core

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×2

ajax ×1

asp.net-core ×1

c# ×1

crud ×1

entity-framework ×1

javascript ×1

jquery ×1

migration ×1