开发者

MVC3 ActionLink nightmare

I have a dashboard page which has 4 partial views. each view has an edit link which when c开发者_C百科licked, loads another temaplate.

Now ofcourse the new template will have Save and Cancel. When I click on cancel, i want to load the old view, and when click on save, i want to save the model and return to the old view.

all this has to be a partial update. How would i achieve this.

To start of with, i am using ajax action link (using post) to just return a datetime string. instead of updating my div, it is redirectin me to a different view. MVC is ridiculously difficult. huh...


Ah.. MVC is simple once you establish a clean way to do things : )

so - each dashboard has 4 partials. So as one option - have your main page have four divs. inside each div, use Html.Partial to render your views. Each partial view has its own Ajax.BeginForm tag. The UpdateTargetId is the divs id in the parent view. I'm not a huge fan of a child needing to know the name of its parent to update, and there are some other ways (one option is each of the four views really is two other views for each one - one to contain the form and div that is updated and then a call to the partial view like:

Each 'parent' partial view has for example


<div id='divAddressEdit'>
@using (Ajax.BeginForm("action","controller",  new AjaxOptions() { UpdateTargetId = "divAddressEdit", InsertionMode = InsertionMode.Replace }){
@Html.Partial(....)
}
</div>

Lets assume you go with the first option where each partial view contains its own ajax form. So - when the user saves - ok.. the ajax form posts back, and then RedirectsToAction() and renders the new content again. When cancel is clicked, the same thing occurs - the form posts and you reload the original info.

The key here are the ajax forms. I know I didn't include much code here - as I believe your post is more of a conceptual question - if it doesn't make sense I'll post specific samples.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜