Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 404123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:16:46+00:00 2026-05-12T17:16:46+00:00

I’ve got a nice MVC app running now, and I’m adding some AJax functionality.

  • 0

I’ve got a nice MVC app running now, and I’m adding some AJax functionality. I have a table which displays 10 items, only certain users can see certain items. When the user adds a new post I’ve set-up the ajax to save the new entry.

However I then need to update the table, I cant find out from JQuery what status the user is (And hence what they can see) so I cant just insert a new row (As some users cant see that row). If this was web-forms I would likly have a page that dumps the table and then i would use JQuery to load the contents of that trimed down ‘page’ into the relevent slot on the current page.

Whats the best way to achieve this with MVC?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:16:46+00:00Added an answer on May 12, 2026 at 5:16 pm

    As @Robert Koritnik suggests, the best way to handle this is using a PartialView. I would suggest having two separate controller actions — one that handles the original request and another that handles the AJAX new entry. Both actions would call the same logic to get the data for the table. The former would put the data into the view model along with other page data. The latter would package the data into a model for the partial view.

    Model classes

    public class PageViewModel
    {
        ....
        public IEnumerable<TableViewModel> TableData { get; set; }
    }
    
    public class TableViewModel
    {
        ...
    }
    

    Controller Code

    [AcceptVerbs( HttpVerbs.Get )]
    public ActionResult Index()
    {
        var model = new PageViewModel();
        model.TableData = GetTableForUser( this.User );
    
        return View( model );
    }
    
    [AcceptVerbs( HttpVerbs.Post )]
    public ActionResult AddEntry( ... )
    {
        ...  add the new entry ...
        var model = GetTableForUser( this.User );
    
        return PartialView( "TableView", model );
    }
    
    
    private TableViewModel GetTableForUser( IIdentity user )
    {
      ...
    }
    

    View Code

    Main View

    <% Html.RenderPartial( "TableView", model.TableData ); %>
    
    <script type="text/javascript">
        $('#entryForm').submit( function() {
            $.post( '<%= Url.Action( "addentry", "controller" ) %>',
                    $('#entryForm').serialize(),
                    function(data) {
                       $('#table').replaceWith( data );
                    },
                    'html' );
            return false;
        });
    </script>
    

    TableView

    <table id="table">
    <% foreach (var row in Model) { %>
        <tr>
         ...
        </tr>
    <% } %>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 441k
  • Answers 441k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't know about creating a .lib file, but you… May 15, 2026 at 5:43 pm
  • Editorial Team
    Editorial Team added an answer The equivalent to FreeAndNil would just be FreeMem(p); p :=… May 15, 2026 at 5:43 pm
  • Editorial Team
    Editorial Team added an answer Did you set HideSelection to false? For some reason the… May 15, 2026 at 5:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.