简体   繁体   中英

How to bind the form data to the model in mvc3

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 model 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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