开发者

Edit Models in different MVC project layer

开发者 https://www.devze.com 2023-02-17 08:54 出处:网络
I have a ASP.NET MVC3 solution named \"SampleProject\". I have 4 projects in the solution. The project names of the solution are

I have a ASP.NET MVC3 solution named "SampleProject". I have 4 projects in the solution.

The project names of the solution are

SampleProject.Data (holds entity classes, DAL classes, and filter classes)

SampleProject.Service (something like BLL in standard ERP)

SampleProject.Tests (test project)

SampleProject.Web (holds controllers and views)

I am calling the Service classes from my controllers. The service classes are calling Data classes and data classes are performing the 开发者_C百科database operations.

I have done create, list and details part. Now I stucked in Edit part. None of the examples (NerdDinner,MVCMusicStore etc) using my architecture. In the provided examples(NerdDinner,MVCMusicStore etc or in ASP.NET website tutorials), they are just using built in UpdateModel method which I don't want to use. I want to manually get the model object from my view and send it to my Data layer for update.

My question is, how can I update the models through different project layer?


I solved the porblem. Here is the code.Just for reference, CResult is a class which contains IsSuccess(bool), Message(string) properties in it.

CResult oCResult;
    [HttpPost]
    public ActionResult Edit(Restaurant model)
    {

        try
        {
            oCResult = restaurantService.Update(model);
            if (oCResult.IsSuccess)
            {
                return RedirectToAction("Index");
            }
            return View("Error");
        }
        catch
        {
            return View();
        }
    }

The view engine prepares the object (in my case, it is Restaurant type of object) it inherits with new values and send back to controller. this is my understanding.

0

精彩评论

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