Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用MVC局部视图时,数据未传递到SQL Server_C#_Jquery_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

C# 使用MVC局部视图时,数据未传递到SQL Server

C# 使用MVC局部视图时,数据未传递到SQL Server,c#,jquery,asp.net-mvc,asp.net-mvc-4,C#,Jquery,Asp.net Mvc,Asp.net Mvc 4,我在局部视图中有一个弹出对话框。当用户单击“创建”按钮时,将显示一个弹出对话框,在弹出对话框中是一个表单,用户在其中键入信息,然后将信息保存到数据库中。我让一切正常,没有任何错误,但我键入的数据没有保存到数据库中 请帮忙,我是编程新手,谢谢 索引页: <li>@Html.Partial("_Create")</li> 在我的家庭控制器中,我将ActionResult创建(从脚手架)更改为_创建: // GET: Home/Creat

我在局部视图中有一个弹出对话框。当用户单击“创建”按钮时,将显示一个弹出对话框,在弹出对话框中是一个表单,用户在其中键入信息,然后将信息保存到数据库中。我让一切正常,没有任何错误,但我键入的数据没有保存到数据库中

请帮忙,我是编程新手,谢谢

索引页:

 <li>@Html.Partial("_Create")</li>
在我的家庭控制器中,我将ActionResult创建(从脚手架)更改为_创建:

        // GET: Home/Create
        public ActionResult _Create()
        {
            return View();
        }

        // POST: Home/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult _Create([Bind(Include = "Id,Title")] Question question)
        {
            if (ModelState.IsValid)
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(question);
        }
请试着换衣服

    @using (Html.BeginForm())
{
}

@使用(Html.BeginForm(“_Create”,“Home”,FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true,“,new{@class=“text danger”})
@LabelFor(model=>model.Title,htmlAttributes:new{@class=“controllabel col-md-1”})
@EditorFor(model=>model.Title,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Title,“,new{@class=“text danger”})
}

并查看调试器在主控制器中使用值调用_Create(post)方法

是否能够在_Create(post)方法中获取模型值?请放一个断点并检查。我把断点放在public ActionResult\u Create(httpPost)上,但没有命中。我不确定是否需要在部分视图中使用Ajax作为弹出对话框窗体。请尝试下面的答案,我已更改了您的窗体,添加了操作名称、控制器名称和FormMethod。还添加了一个提交按钮eah,它可以工作。非常感谢。
        // GET: Home/Create
        public ActionResult _Create()
        {
            return View();
        }

        // POST: Home/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult _Create([Bind(Include = "Id,Title")] Question question)
        {
            if (ModelState.IsValid)
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(question);
        }
    @using (Html.BeginForm())
{
}
@using (Html.BeginForm("_Create","Home",FormMethod.Post))
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-1" })
            <div class="col-md-11">
                @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })

                <input type="submit" value="submit"/>
            </div>
        </div>
    </div>
}