Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.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# '的Post参数;编辑';动作总是空的_C#_Asp.net Mvc - Fatal编程技术网

C# '的Post参数;编辑';动作总是空的

C# '的Post参数;编辑';动作总是空的,c#,asp.net-mvc,C#,Asp.net Mvc,控制器: public ActionResult Edit(int id) { SetViewData(); var rule = _db.AlertRules.Find(id); ViewData["rule"] = rule.Feed.Name + " - " + rule.Template.Name; return View(rule); } // // PO

控制器:

    public ActionResult Edit(int id)
    {
        SetViewData();
        var rule = _db.AlertRules.Find(id);

        ViewData["rule"] = rule.Feed.Name + " - "
            + rule.Template.Name;
        return View(rule);
    }

    //
    // POST: /AlertRule/Edit/5
    [HttpPost]
    public ActionResult Edit(AlertRule alertrule)
    {
        SetViewData();
        alertrule.UpdateDateTime = DateTime.Now;
        if (ModelState.IsValid)
        {
            _db.Entry(alertrule).State = EntityState.Modified;
            _db.SaveChanges();
            return RedirectToAction("Index");
        }
        else
        {
            TempData["error"] = "Cant update rule({0})"
                + alertrule.Id;
        }

        return View(alertrule);
    }

    private void SetViewData()
    {
            var feeds = new SelectList(_db.Feeds.OrderBy(f => f.Name), "Id", "Name");
            var templates = 
                 new SelectList(_db.AlertRuleTemplates.OrderBy(f => f.Name), "Id", "Name");

            ViewData["templates"] = templates;
            ViewData["feeds"] = feeds;
    }
视图:


这是一个常见的问题。模型中似乎有一个
Alertrule
属性与操作参数名称冲突。因此,请重命名您的操作参数:

[HttpPost]
public ActionResult Edit(AlertRule model)
或者重命名
AlertRule
属性名称以避免冲突

问题在于以下属性:

Alertrule:00000

由于操作参数的调用方式与默认模型绑定器尝试将值
00000
绑定到
alertRule
参数的调用方式相同,因此显然失败。

这是常见的问题。模型中似乎有一个
Alertrule
属性与操作参数名称冲突。因此,请重命名您的操作参数:

[HttpPost]
public ActionResult Edit(AlertRule model)
或者重命名
AlertRule
属性名称以避免冲突

问题在于以下属性:

Alertrule:00000

由于调用动作参数的方式与调用默认模型绑定器的方式相同,因此默认模型绑定器试图将值
00000
绑定到
alertRule
参数,该参数显然失败。

@DarinDimitrov all。post方法的参数为null,[HttpPost]公共操作结果编辑(AlertRule AlertRule)@DarinDimitrov all。post方法的参数为null,[HttpPost]公共操作结果编辑(AlertRule AlertRule)