Updating the model in the controller?

I am using ASP.NET MVC 3. I have a question, is it possible to update the model even if it is not sent to the controller? Perhaps the question is completed, or am I doing something wrong?

I have an ajax call to a controller method. I pass the identifier. I would like the controller to find some things in db, and then update the model, passing it back to the view.

I have a pretty big model ... I found some solutions where you can convert the model into a javascript object and send it to the controller. Is this the only / correct way?

How to send model to jQuery $ .ajax () request for MVC controller method

I thought that maybe the controller has a model where I could update some fields in it?

Controller call:

    function getBis(id) {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetBis")',
            data: { "id": id },
            dataType: 'json',
            cache: false,
            success: function (data) {
                // Do something here
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Problem!");
            }
        });
    }

Controller Code:

    public ActionResult GetBis(string id)
    {
        BeslutIStortDTO viewModel = new BeslutIStortDTO();

        int theId;
        if (!Int32.TryParse(id, out theId))
            throw new Exception("Wrong id");

        viewModel = _blLayer.GetBIS(theId);

        // somehow update the model here!

        return View("index", viewModel);
    }
+3
3

" " JQuery , "" , - , (MVC , , ), , , - . , , , ID , .

jquery ajax

0

, , , ? . .

GetBis, .

Javascript, JSON Result.

return JSON(viewModel);

, , .

0

: "" "", , , . , , View Model. .

, , - .

, .

- , , HTML, View. - , .

Ajax , , , , , Domain ( Id), View Model, ( ).

.

, . Person {long id = 1; string name = bob; bool enabled = true}

( bob get get get) PersonData {long id = 1; string name = "bob", enabled = true}

, GET-, , , ( "EditPerson" ), pd), HTML, , .

HTML- -, IT. . Ajax, , , , " ", , , ( ) ajax, , bob. Entity Entity , .

VIEW, , .

- , , ?

0

All Articles