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 8230915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:17:48+00:00 2026-06-07T17:17:48+00:00

I am trying to update a partial view using ajax, but for some reason

  • 0

I am trying to update a partial view using ajax, but for some reason its failing.

Controller:

[HttpPost()]
public ActionResult DisplaySections(string id)
{
    DataContext db = new DataContext();

    var Data = (from p in db.vwData.Where(a => a.CourseId == id)
                          group p by p.SectionId into g
                          select g.Key).ToList();

    return PartialView("DisplaySections", Data);
}

Ajax:

$('#CourseId').focusout(function (e) {
    e.preventDefault();
    var link = '/Course/DisplaySections';
    $.ajax({
        type: 'POST',
        url: link,
        data: { id: $('#CourseId').val() },
        dataType: 'html',
        success: function (result) {
            $("#partial").html(result);
        },
        error: function (result) {
            alert("Failed")
        }
    });
});

Partial:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="Course.Models" %>

<table>
<% if (Model != null)
           foreach (var item in Model) {
           if (item == null) continue; %>

        <tr>
            <td>
                <%: item.SectionId%>
            </td>
            <td>
                <%: item.Description%>
            </td>            
        </tr>

    <% } %>

    </table>

Master View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="Course.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Course - Sections
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div style="text-align: left; height: 202px;">
<table>
<tr>
    <th>Course Id</th>
    <td><input type="text" name="CourseId" id="CourseId"/></td>
</tr>
<tr>
    <th>Course Name</th>
    <td><input type="text" name="CourseName" id="CourseName"/></td>
</tr>
</table>

<div id="partial">
<% Html.RenderPartial("DisplaySections"); %>
</div>

</div>

</asp:Content>
  • 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-06-07T17:17:50+00:00Added an answer on June 7, 2026 at 5:17 pm

    Your partial view is full of errors.

    Your controller action passes a List<string> (or List<int> depending on the type of the SectionId property) to this view:

    [HttpPost()]
    public ActionResult DisplaySections(string id)
    {
        DataContext db = new DataContext();
    
        List<string> data = 
            (from p in db.vwData.Where(a => a.CourseId == id)
             group p by p.SectionId into g
             select g.Key).ToList();
    
        return PartialView("DisplaySections", data);
    }
    

    and yet in your partial view you are attempting to use some item.SectionId and item.Description.

    Start by making your view strongly typed so that you have Intellisense showing you what you can and cannot use at compile-time:

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<List<string>>" 
    %>
    
    <table>
        <% if (Model != null) { %>
            <% foreach (string item in Model) { %>
                <% if (item == null) continue; %>
                <tr>
                    <td>
                        <%: item %>
                    </td>
                </tr>
            <% } %>
        <% } %>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to update a model using jQuery AJAX by passing a JSON
I have a strange problem. I am trying to update some fields using linq
I trying to update a model on a callback but the validation is causing
Im trying to update the contents of an element after running some php code.
I am trying to create a partial view I call ImageViewer. It will be
I'm using ajax and trying to pass the Model back, which is a generic
I'm trying to create an MVC view that will display some data in a
I am using Asp.net MVC3 and trying to do a simple Ajax post to
I am trying to make an ajax sending data in JSON from a partial
I am using Loading a partial view in jquery.dialog as a reference in order

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.