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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:56:19+00:00 2026-06-06T01:56:19+00:00

I am new to .net MVC structure. I am trying to create Partial view

  • 0

I am new to .net MVC structure. I am trying to create Partial view (like user control in traditional asp.net) where I pass Id and it displays jqgrid based on value.

When I add tag with in Partial view to load Jqgrid using jqery and call controller’s method it works. But when i move that code to .js file jqgrid doesn’t load.

Index View

   @model Compass.Models.Sales
@{
    ViewBag.Title = "Lead Details";
}
@section  Css {
    @Content.Css("themes/base/jquery-ui.css", Url)
    @Content.Css("jquery.jqGrid/ui.jqgrid.css", Url)
}
@section JavaScript {
       @Content.Script("jquery-ui.multiselect.js", Url)
       @Content.Script("jquery.tmpl.min.js", Url)
       @Content.Script("i18n/grid.locale-en.js", Url)
       @Content.Script("jquery.jqGrid.min.js", Url)

}  
<div><h3>Lead Details # @ViewBag.LeadID</h3></div>

@using (Html.BeginForm()) { 
    @Html.ValidationSummary(true, "Please correct error/s and try again.");
<div>
<table>
    <tr>
        <td>@Html.LabelFor(m=>m.OwnerID,"Owner:") </td> <td>@Model.OwnerID</td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m=>m.StatusID, "Status:") </td> <td>@Model.StatusID</td><td>@Html.LabelFor(m=>m.RatingID, "Rating:") </td> <td>@Model.RatingID</td>
    </tr>
</table>
</div>
<p></p>


@Html.Partial("_Notes", Model)
}

Partial View (_Notes.cshtml)

@Html.RequireScript("/Scripts/NotesView.js")
<h4>
    Notes for Lead # @Model.ID</h4>
<div style="width: 90%">
    <table id="jqgNotes" style="width: 100%">
    </table>
    <div id="jqgpNotes" style="text-align: center; width: 100%">
    </div>
</div>
<div id="editNote">
</div>

NotesView.js : which loads the jQgrid in JqgNotes table element.

  $(document).ready(function () {
            alert('testing');
            $('#jqgNotes').jqGrid({
                //url from wich data should be requested
                url: '@Url.Action("getNotes")',
                //type of data
                datatype: 'json',
                //url access method type
                mtype: 'POST',
                postData: {
                    UnitID: '@Model.ID'
                },
                //columns names
                colNames: ['Title', 'Last Modified', 'Last Modified By', 'Edit'],
                //columns model
                colModel: [

                                { name: 'Title', index: 'Title', align: 'left', search: true, stype: 'text', editable: true, edittype: 'text' },
                                { name: 'UpdatedDate', index: 'UpdatedDate', align: 'left', formatter: 'date', formatoptions: { srcformat: 'm/d/Y h:i:s', newformat: 'm/d/Y h:i:s' }, sorttype: "date", datefmt: "m/d/Y h:i:s", search: true },
                                { name: 'UpdatedBy', index: 'UpdatedBy', align: 'left', search: true },
                                { name: 'Edit', index: 'Edit', align: 'center', formatter: supplierFormatter, unformat: supplierUnFormatter, editable: false },
                              ],
                //pager for grid
                pager: $('#jqgpNotes'),
                //number of rows per page
                rowNum: 10,
                //initial sorting column
                sortname: 'UpdatedDate',
                //initial sorting direction
                sortorder: 'desc',
                //we want to display total records count
                viewrecords: true,
                //grid height
                height: '100%',
                autowidth: true
            });
 function supplierFormatter(cellvalue, options, rowObject) {
            return "<a href='#' data-edit-id='" + options.rowId + "'>Edit</a>&nbsp;&nbsp;<a href='#' data-delete-id='" + options.rowId + "'>Remove</a>";
        };
        function supplierUnFormatter(cellvalue, options, cellobject) {
            return cellvalue;
        };

        $('#jqgNotes').jqGrid('navGrid', '#jqgpNotes',
                { editfunc: function (rowid) {
                    editNoteFunc(rowid);
                    return false;
                }
                },
                {}, // Edit Option
                {}, // add option
                {}, // delete option
                {} // search option
            );

When I have .js code with in _notes.chtml as tag page loads fine. It executes controllers “getNotes” Method but when i move this JavaScript code into .js file and loads its i can still see the alerts coming but controllers “getNotes” method doesn’t get executed. I put breakpoints on that method but it never reach to that.

I would really appreciate if you can help me. Either my approach is not right or there is something i am doing is not right. Basically, I want to create partial view which can gets its data (using jquery) by its own so i plug this view to any other page.

  • 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-06T01:56:20+00:00Added an answer on June 6, 2026 at 1:56 am

    You seem to be using server side helpers in your external javascript file such as url: '@Url.Action("getNotes")' and UnitID: '@Model.ID' which obviously doesn’t work. Javascript are static files and server side helpers do not run. So you will have to pass those values to the script as arguments.

    So for example you could use HTML5 data-* attributes inside the view:

    <table id="jqgNotes" style="width: 100%" data-url="@Url.Action("getNotes")" data-unitid="@Model.ID">
    </table>
    

    and then inside your javascript file you could use this value with the .data() function:

    url: $('#jqgNotes').data('url')
    

    and:

    postData: {
        UnitID: $('#jqgNotes').data('unitid')
    }
    

    Notice how there’s no longer the @ Razor server side function used in the static javascript file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the following project structure for my new asp.net mvc project any
I have a new asp.net mvc project and i am trying to figure out
I created a new ASP.NET MVC application. The home page looks like this: I
Some background: I create a new ASP.NET MVC 3 WebApplication. Then I add a
I'm trying to decide what validation approach to take for a new ASP.NET MVC
I'm trying to build an ASP.NET MVC 2 application. I want to pass data
Environment: ASP.net MVC: Given anonymous structure as such: var test = new { name
Firstly, I'm new to MVC - and trying out ASP.NET MVC3. I want to
Lets consider default ASP.NET MVC application folder structure, so it's looks like this: -App_data
I am new to ASP.Net MVC 3, facing some issues while trying to implementing

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.