Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-12-05
3
Medium Priority
?
648 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
ID: 40485080
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
ID: 40485955
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
ID: 40495797
Figured it out myself
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

773 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