开发者

How to bind the form data to the model in mvc3

开发者 https://www.devze.com 2023-01-30 09:02 出处:网络
I\'m trying to make an Edit in mvc 3 Here is the code I have public ActionResult Edit(int id, FormCollection collection)

I'm trying to make an Edit in mvc 3

Here is the code I have

public ActionResult Edit(int id, FormCollection collection)
        { 
            if (ModelState.IsValid)
            {
                try
                {
                    sea loadedSea = BskDB.loadSea(id);

                    loadedBskSeason.UpdateFrom()//Error Here

                    return RedirectToAction("Index");
                }
                catch
                {
                    return View("EditSea");
                }
            }
            return View("EditSea");
        }

This article says that the

"UpdateFrom" extension method to automatically populate our product object from the request.

But in my case it gives me a compilation error - No extension method can be found

In this other article it says that the UpdateFrom has been change to

loadedSea.UpdateFrom(Request.Form);

to:

BindingHelperExtensions.UpdateFrom(loadedSea, Request.Form);

But also this doesn't work.

Any examples on how to do bindings from a collection to a mo开发者_如何学编程del in MVC 3?

Thanks


That ScottGu article refers to a prerelease version of MVC 1 and a lot has changed since then. You might want to look into the TryUpdateModel family of methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消