2 wjj ghming wjj_GHMING 于 2017.09.05 15:15 提问

asp.net mvc <input type="submit"/> 无效

在把asp.net mvc的控制器Edit方法和View代码完全复制到一个其他地方时,代码仍能很好的执行.
现在我想通过这个Edit方法修改部分信息,即不需要修改所有可能的列.
所以我删除了View中的一些输入框,比如这样的


@Html.LabelFor(model => model.CardUserName, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.EditorFor(model => model.CardUserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CardUserName, "", new { @class = "text-danger" })


然后只剩下我想改的那一项,这时候

按钮就失效了.
想请教为什么QAQ
其实我对这个按钮真的不是很懂,希望大家能给尽可能详细的回答和知道,提前感谢

3个回答

caozhy
caozhy   Ds   Rxr 2017.09.05 15:16

你的模型绑定可能有些问题,你可以自己去获得值
ActionResult 动作方法(FormCollecation fc)
{
string s = fc["CardUserName"];
...
}

wjj_GHMING
wjj_GHMING 初用CSDN...我下面贴了些代码...麻烦你帮忙看下
3 个月之前 回复
wjj_GHMING
wjj_GHMING   2017.09.05 15:22

@caozhy
这个是控制器代码qwq

public ActionResult Zhuanrang(string id)         {             if (id == null)             {                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);             }             MembershipCard msCard = db.MembershipCards.Find(id);             if (msCard == null)             {                 return HttpNotFound();             }             return View(msCard);         }                [HttpPost]         [ValidateAntiForgeryToken]         public ActionResult Zhuanrang([Bind(Include = "CardUserName")] MembershipCard msCard) //这个地方是模型绑定?        {             if (ModelState.IsValid)             {                 db.Entry(msCard).State = EntityState.Modified;                 db.SaveChanges();                 return RedirectToAction("MyCard");             }             return View(msCard);         }
wjj_GHMING
wjj_GHMING ......好乱
3 个月之前 回复
wjj_GHMING
wjj_GHMING   2017.09.05 15:24
    public ActionResult Zhuanrang(string id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        MembershipCard msCard = db.MembershipCards.Find(id);
        if (msCard == null)
        {
            return HttpNotFound();
        }
        return View(msCard);
    }
    //会员卡转让
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Zhuanrang([Bind(Include = "CardUserName")] MembershipCard msCard)
    {
        if (ModelState.IsValid)
        {
            db.Entry(msCard).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("MyCard");
        }
        return View(msCard);
    }
Csdn user default icon
上传中...
上传图片
插入图片