简体   繁体   English

如何通过C#ASP.NET MVC4更新数据库?

[英]How to update database by C# ASP.NET MVC4?

I have a problem like this. 我有这样的问题。 I've to update the ContenuReponse to database. 我必须将ContenuReponse更新为数据库。 In View of ContenuReponse, I have: 鉴于ContenuReponse,我有:

<div class="editor-field">
        @Html.EditorFor(model => model.ContenuReponse)
        @Html.ValidationMessageFor(model => model.ContenuReponse)
    </div>

(I use express of the template MVC4 Internet App of Edit View for the textbox) and in Controller of Reponse I have: (我在文本框中使用的是Edit View模板MVC4 Internet App的express),在响应控制器中,我有:

public ActionResult Reponse(int id = 0)
    {
        Question question = db.Questions.Find(id);
        if (question == null)
        {
            return HttpNotFound();
        }
        return View(question);
    }

    [HttpPost]
    public ActionResult Reponse(Question question)
    {

    }

What should I have to do in 我该怎么办

[HttpPost]
    public ActionResult Reponse(Question question)
    {

    }

to get the value from textbox of View. 从View的文本框中获取值。 Any Ideas ? 有任何想法吗 ? Thanks a lot for the attention! 非常感谢您的关注!

In the action method 在行动方法

[HttpPost]
public ActionResult Reponse(Question question)
{

}

in the Question question argument all the values will be posted to here from the view. 在问题问题参数中,所有值将从视图中发布到此处。 You can then use will value and insert it to database. 然后,您可以使用will值并将其插入数据库。 To insert to database I recommend you to use Entity Framework, do a little googling on the same. 要插入数据库,我建议您使用实体框架,对其进行一点搜索。

Also the best way to understand is to create a breakpoint in this method and see the values posted to the Question question parameter 最好的理解方法是在此方法中创建一个断点,并查看发布到Question问题参数中的值

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM