Solved

MVC 4 webGrid on main view disappears when ajax.actionlink is clicked to load a partial view.

Posted on 2014-12-05
3
582 Views
Last Modified: 2014-12-12
This is what I want to happen: User click an item in the grid and that items is loaded above the grid, the grid does not change.

This is what happens:  User click an item in the grid and that items is loaded above the grid, the grid disappears.

I have the grid in the main view and the item display portion in a partial view.

I'm kind of an MVC newbe, so if this in not the correct way to do this what is?

ThankssampleCode.txt
0
Comment
Question by:Bob Hoffman
  • 2
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Is this the code that has the Ajax.ActionLink that you are referring to?

   @using (Html.BeginForm("_Grid", "MyModel"))
    {
        <div>
            @grid.GetHtml(

                    columns: new[] 
                    {
                         grid.Column(header: "Id", canSort: false, format: (item) => Ajax.ActionLink(((int)item.RecId).ToString(), "_editPartial", "MyModel", new {recId = item.RecId}, new AjaxOptions { UpdateTargetId = "_editPartialDiv"})),
                })
        </div>
    }

Open in new window

0
 
LVL 8

Accepted Solution

by:
Bob Hoffman earned 0 total points
Comment Utility
Got it figured out. Changed the grid column to an anchor that executes an async GET via ajax. Not really sure why this works over the ActionLink which is also doing an async GET via ajax... but it does.


GRID LINK COLUMN

grid.Column(header: "Id", format:@<text> <a href="javascript:loadEditDiv(@item.RecId);" id="Edit_@item.RecId">@item.RecId</a></text>)

JAVASCRIPT
        function loadEditDiv(RecId) {
            $.ajax({
                type: "GET",
                cache: false,
                url: "@Url.Action("_editPartialDiv", "MyModel")",
                data: { RecId: RecId },
                dataType: "html",
                async: true,
                success: function (data) {
                    $("#_editPartialDiv").html(data);
                }
            });
0
 
LVL 8

Author Closing Comment

by:Bob Hoffman
Comment Utility
Figured it out myself
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now