Diego
Diego

Reputation: 2362

MVC 5 jquery change value form other View

I am developing an MVC 5 App.

I have defined in the_Layout a View that is the Header, another that is the Body and the Footer like this...

<div>
    @Html.Action("Header", "Home")
</div>

<div>
    @RenderBody()
    <footer>
        @Html.Partial("~/Views/Home/Footer.cshtml")
    </footer>
</div>

on Body I load a View that Execute an @Ajax.BeginHtml. It returns a Json on success.

What I need, in order to not Load() all the page, is to change a @Html.Editor of Header.cshtml from the Body.cshtml using Jquery on success method

Is that posible ?

Thanks

Upvotes: 0

Views: 103

Answers (2)

marcokreeft
marcokreeft

Reputation: 296

If you set the UpdateTargetId to the element containing the editor and set to action to return a partialview with the editor in it.

For example

@using (Ajax.BeginForm("MyAction", "MyController",
        new AjaxOptions
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "target"
        })) { }

where UpdateTargetId is the element containing the Editor.

Upvotes: 1

Federico Alecci
Federico Alecci

Reputation: 914

Yes, you can. @Html.Editor just renders some html markup so you could changed its content using jQuery. You won't be able to change the strongly-typed model from it with jQuery, if that's your case.

Could you provide an example of what you are trying to achieve?

Upvotes: 0

Related Questions