Partial view datasource url for different areas not working as expected

2 posts, 0 answers
  1. Sam
    Sam avatar
    1 posts
    Member since:
    Oct 2013

    Posted 19 Jun 2014 Link to this post


    Scenario:

    I have a kendo ui panel bar in a view within an area(say MyArea) which has kendoComboBox (partial view) from a different area(say Services)

    @(Html.Kendo().PanelBar()
            .Name("PanelBar")
            .Items(search =>
                {
                    search.Add()
                        .Text("Search YLAU EdiLog")
                        .Expanded(true)
                        .Content(@<text>
                                    <form method="post" id="myForm">
                                              <div class="TableCell">@Html.Partial("~/Services/Views/Customer/WMSCustomerList.cshtml")  </div>

         
    WMSCustomerList.cshtml(partial view):

    <script type="text/javascript">

        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url:"Services/Customer/WMSCustomerList",
                    dataType: "json"                  
                }
            }
        });
        $("#Company").kendoComboBox({
            dataSource: dataSource,
            dataTextField: "AccountName",
            dataValueField:"AccountCode"
        })

    Issues:

    - The url specified for the kendo combo box does not gets called i.e, the controller from a different area(Services) does not get called. 

    Q: How do you call a datasource from different areas in a partial view ?


    - I changes the datasource url by adding a slash in the start of the url (url:"/Services/Customer/WMSCustomerList",) which then works correctly. 

    Q: What is the significance of adding a slash in front of the url? Why doesn't the url area switching work without a slash? Please clarify

    Thanks!



        



  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 24 Jun 2014 Link to this post

    Hi Sam, 

    The slash signifies whether the URL should link to the root path, or to the current one. For example: 
    <a href="/test">Test link</a> ===>  localhost/test
    <a href="test" >Test link</a> ===>  localhost/Area/Controller/test
    It is generally recommended to use the Url helper instead of hard-coded links. For example: 
    Url.Action("View", "Controller", new { area="areaName" })

    Regards,
    Alexander Popov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top