开发者

Return several partial views within a main view, based on actions in the partial views

I have this view based on person model which is an entity model.

@model TestApp.Models.Person

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

@Html.Partial("../PersonContactData/Create");

Then My PersonContactData controller returns the partial view "Create" which has a form and a submit button. When I press that submit button I do a redirectToAction to Index from the PersonContactData controller and I want to return the view from Index to the page described above.

How Do I do that?

And I want all this to happen without the page refreshing. I can pass all values with ajax but I need some 'container' or something to actually take the partial views (list, create, edit,.. from PersonContactData) that are being returned to the main view which is based on Person model. In other words that the actions, their corresponding partial views and their functionality can work within a page that is based on another model (Person) and controller (PersonController)

This is for example an ajax post function I used to get the values from the create view. This works, but still I want to redirect to action Index in my HttpPost Create action and return the View for Index, as it should work. But my main View (based on Person model) won't display it.

function ACGetList() {
        var personContactData = {
            ContactType: $('#ddlContactDataType').val(),
            Value: $('#txtContactDataValue').val()
        };
        $.ajax({
            url: '/PersonContactData/Create',
      开发者_JAVA百科      type: 'POST',
            data: JSON.stringify(personContactData),
            dataType: 'Json',
            contentType: 'application/json; charset=utf-8',
            success: function () { },
            error: function () { }
        });
    }


OK as far as I know.

An MVC system is a serverside structure or frame work. M=Model, V=View,C=Controller.

Models are validations, db etc, View are markups,json,css,xml etc... Controllers, are php,asp, so u can say what to show when.

As far as I understand your question you are simply just asking use ajax.

What ajax does is requests a page and retruns some data or all of it to the main page using js. Check out jQuery .ajax function or google it.

so lets say ur home page is:

mysite.com returns <h1>Hello World!</h1>

Then ajax page has <p>I am ajax</p>

then on home page using js/jq you can tell where you want "i am ajax" to go to

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜