Tag Archives: Menu

Menu

[RESOLVED]AngularJS in ASP.NET MVC Partial View

I am currently loading Partial View returned by MVC controller to a model dialog via AngularJS $http.get call. My View in rendered properly in modal dialog, but the only problem is that my partial view which is rendered also uses angular expressions etc.
and for some reason angular is not working in my partial view, but if i load this partial view in some other view without ajax call then it angular works properly.

Partial View Code: ~/Views/ArticleType/_Add
MVC Controller: ArticleTypeController

//other scripts files e.g app.js and angular.js are included in main layout file.
<script src="~/Scripts/Angular/ArticleTypeController.js"></script>
<div class="modal-content" ng-controller="ArticleTypeController">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        Add New Article Type
    </div>
    <form novalidate role="form" name="ArticleTypeForm" ng-submit="ArticleTypeForm.$valid && Add(model)">
        <div class="modal-body">
            <div class="form-group">
                <label for="ArticleType" class="control-label">Article Type</label>
                <input type="text" required ng-model="model.ArticleTypeName" class="form-control" id="ArticleType" />
            </div>
        </div>
 
    </form>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary" value="Add" >Add</button>
        {{ArticleTypeForm.$valid}}
    </div>
</div>

Angular Controller to load modal with the partial view.
MenuController.js

angular.module('myApp').controller('MenuController', [
        '$scope', '$http', 'httpPreConfig', function ($scope, $http, httpPreConfig) {
 
            $scope.AddArticleType = function () {
                $.get("/ArticleType/Add")//returns the partial view.
                    .success(function (response) {
                        ShowModal(response);//it properly shows the modal. but angular doesn't work
                    });
            }
        }]);

common.js 

$(document).ready(function (e) {
    
    $(document).ajaxStart(function (e) {
        $("#loadingBar").modal('show');
    });
    $(document).ajaxStop(function(e) {
        $("#loadingBar").modal('hide');
    });
    $(document).ajaxComplete(function (e) {
        $("#loadingBar").modal('hide');
    });
    $(document).ajaxError(function (e) {
        $("#loadingBar").modal('hide');
    });
});
 
function ShowModal(content) {
 
    //var html = $complie(content)(scope);
    $("#modal .modal-dialog").html(content);
    $("#modal").modal("show");
}
function HideModal() {
    $("#modal .modal-dialog").html("");
    $("#modal").modal("hide");
}

AS you can see from the image below that Angular expressions are not working in Modal Dialog. The html of this dialog is returned from MVC Controller whcih returns a partial view. 

Any help would be really appreciated. Just so that you know, angular expressions etc. are working in normal views.

Here is the download link to the solution files. : https://app.box.com/s/rxvrhwcdp75zo736k7u5

Hi asad,

According to your description, it works fine if you load that partial view directly, however it doesn’t work if using the AJAX to load the partial view.

I think you may need to compile HTML string or DOM into a template.

More information, please refer to:

# $compile

https://docs.angularjs.org/api/ng/service/$compile  

There are some threads that may help you:

# AngularJS – Dynamically creating elements that specify directives

http://stackoverflow.com/questions/20025526/angularjs-dynamically-creating-elements-that-specify-directives

# Bind Angularjs to newly created html element dynamically

http://stackoverflow.com/questions/19867554/bind-angularjs-to-newly-created-html-element-dynamically

Best Regards

Starain Chen

[RESOLVED]Need help to create Cascading DropDownList using MVC4 – C# from Database

I have 2 dropdown lists  (State and City) in my form and I want to show them as Cascading DropDownList.

When I select a State then I want to display only the related cities in that state.

My mode:

public class AustraliaStates
    {
        [Key]
        public string AustraliaStateId { get; set; }
        public string AustraliaStateName { get; set; }
    }

    public class AustraliaCities
    {
        [Key]
        public string AustraliaCityId { get; set; }
        public string AustraliaCityName { get; set; }
    }



    public class Accommodation
    {
        [Key]
        public string A_Unique_Id { get; set; }

        [Display(Name = "Street")]
        public string Street { get; set; }

        [Required]
        [Display(Name = "Suburb")]
        public string Suburb { get; set; }

        [Display(Name = "City")]
        public string City { get; set; }

        [Display(Name = "State")]
        public string State { get; set; }

        public string SelectedAustraliaStateId { get; set; }
        public IEnumerable<SelectListItem> AustraliaStates { get; set; }


        public string SelectedAustraliaCityId { get; set; }
        public IEnumerable<SelectListItem> AustraliaCities { get; set; }
    }

Create.cshtml Get controller:

// GET: /Accommodation/Create
        [Authorize]
        public ActionResult Create()
        {

            var model = new Accommodation
            {
                AustraliaStates = db.AustraliaStates
                             .ToList() // this will fire a query, basically SELECT * FROM Products
                             .Select(x => new SelectListItem
                             {
                                 Text = x.AustraliaStateName,
                                 Value = x.AustraliaStateId
                             }),

                AustraliaCities = db.AustraliaCities
                             .ToList() // this will fire a query, basically SELECT * FROM Products
                             .Select(x => new SelectListItem
                             {
                                 Text = x.AustraliaCityName,
                                 Value = x.AustraliaCityId
                             });
                


            return View(model);
        }

Create.cshtml View

<td class="FormDisplayRightTableStyle">
                                <div class="editor-field">
                                    @Html.DropDownListFor(model => model.SelectedAustraliaStateId, Model.AustraliaStates, new {@class="DropDownFieldStyle" })

                                </div>
                            </td>    
                        </tr>

                        <tr>
                            <td class="FormDisplayLeftTableStyle">
                                <div class="editor-label">
                                    @Html.LabelFor(model => model.City)
                                </div>
                            </td>
                            <td class="FormDisplayRightTableStyle">
                                <div class="editor-field">
                                    : @Html.DropDownListFor(model => model.SelectedAustraliaCityId, Model.AustraliaCities, new {@class="DropDownFieldStyle" })
                                </div>
                            </td>    
                        </tr>

I need to solution to show the DDL as Cascading DropDownList.

can someone please help me?

Thanks in advance.

Here is the form I am working on:

http://overseasindians.com.au/Accommodation/Create

Typical cascading dropdown lists only load the first list initially.  So in your case, you would load your States to the view.  Upon selecting a state, a JSON get-request is made back to your controller, where you’ll return a list of cities based on the
selected state.  Your Cities dropdown will also be hidden at the start, but will be revealed once a country is selected.  Also, you don’t want to return a model based on your two lists because a Create view needs to reserve a model specifically for the form
elements of the View.

public ActionResult Create()
{
  var states = db.Australiastates.ToList();

  ViewBag.stateList = states;

  return View();
}

In the above action, we create a list of States and pass them to the view as a ViewBag object.  We do NOT return any model to the view.

Now we create the View:

@model AppName.Models.YourFormModel

@section scripts {
  <script type="text/javascript">
    $("#Cities").hide();

    $("#States").on("change", function () {

// make the get-request
$.getJSON('@Url.Action("GetCities")', { id: $(this).val() }, function (cities) {

// populate the Cities dropdown with returned data
$.each(cities, function (i, city) {
$("#Cities").append('<option value="' + city.AustraliaCityId + '">' + city.AustraliaCityName + '</option>');
});

});

// show the Cities dropdown
$("#Cities").show();

}); </script> } <div> @Html.DropDownList("States", new SelectList(ViewBag.stateList, "AustraliaStateId", "AustraliaStateName"), "Select a state") </div> <div> <select id="Cities" /> </div>

In the above view, we have a dropdown list for both States and Cities, however you’ll notice that the Cities dropdown list is just a generic <select> element.  This is because we didn’t initially pass any data from the Create action to the view, so there’s
no reason to have the DropDownList helper.  We also have a "scripts-section" at the top, with a <script> block and some code inside.  The code is jQuery.  the first line hides our Cities dropdown because it will initially be empty, so it doesn’t need to be
shown immediately.  The 2nd part of the script is an on-change event for the States dropdown list.  On-change, we make a call to an action named "GetCities" where we pass an "id" param of the states dropdown value.  The action will use this param to find all
cities associated with the ID and return it back to the View.  Once the data is returned, we populate the Cities dropdown list, and then show the dropdown list so it can be visible.

Next, we need to add the "GetCities" action to take the State ID and return a list of Cities:

[HttpGet]
public ActionResult GetCities(int id)
{
  var cities = db.AustraliaCities.Where(c => c.State_ID == id).ToList();

  return Json(cities, JsonRequestBehavior.AllowGet);
}

This action should be fairly obvious.  We used the state’s ID to gather a list of cities.  The only issue I had with this is that I didn’t see a "StateID" property in your AustraliaCities model, though I feel there should be one to create an association
between City and State.  I’ll let you determine how to use the state’s ID in the action to populate your Cities list.  In any case, once you have your list of cities, you return it as a JSON result.

That’s all there is to it.  This is a complete working solution.  Please let me know if you have questions.

Hi athelli_,

Thanks for your post.

athelli_reddy

Need help to create Cascading DropDownList using MVC4 – C# from Database

You can use JQuery, Please refer to this link:

#Creating cascading dropdownlists using MVC 4 And JQuery

http://jnye.co/Posts/12/creating-cascading-dropdownlists-using-mvc-4-and-jquery

Hope this can be helpful.

Best Regards,

Eileen

Thank you very much John for detailed explanation & your solution is working.

Can you please let me know how can I make State Dropdown menu field as a Mandatory field and show a client side validation if when the dropdown contains "Select a state" value.

public class AustraliaStates
    {
        [Key]
        public string AustraliaStateId { get; set; }
        
        [Required]  ->what else I can add here to make it as a Mandatory if there is "Select a state" value
        public string AustraliaStateName { get; set; }
    }

or do I need to write any java script??

[RESOLVED]Layout Needs a Model

Hi All,

I am working on a project for which the UI was created by someone else.  The project has a Partial View called _ApplicationLayout.cshtml that renders on every view page in the project.   It also hosts several partial views, one of which is the "_Comments.cshtml"
view in which I need to display all of the comments from the database that are associated with the application in the right bar of the layout.  I cannot use a View Model in the _Comments.cshtml partial, because it is rendered in the _ApplicationLayout.cshtml
and of course the View Model clashes with all of the other View Models throughout the project.  Can anyone tell me just how can solve this problem?  The comments do need to show on every page (view) in the project.

You can do it via two different ways,

  1. Call @Html.RenderAction  rather than partial to render the result of an action method, that will give you chance to separate out the code with strongly typed model
  2. Create a base controller and initialize the data and assign it to ViewBag which is required for comments view, now all controllers will inherit from base controller and they will have the data available.

I would prefer the first approach as it is a MVC way of doing things and avoid any accidental miss of controller inheritance.

Either move the comments-partial to the actual View, or replace the Partial helper with an Action helper and pass it an ID/value to process data and return a partial view

Example–

Instead of:

@Html.Partial("_Comments")

do:

@Html.Action("GetComments", new { id = X })

where X could be a ViewBag.Value or a URL parameter, example:

@Html.Action("GetComments", new { id = ViewBag.BlogID })

public ActionResult GetComments(int id)
{
  var comments = db.Comments.Where(c => c.BlogID == id).ToList();

  return PartialView("_Comments", comments);
}

The problem is that there  will be a list of comments, and there is a "textarea" for adding more comments on the fly.  Will the solution you suggested still work?  I don’t have the option of moving the Partial out of the _ApplicationLayout.cshtml.  Also,
how can I specify the controller where the ActionResult is in the code:

@Html.Action("GetComments"new { id = ViewBag.loanApplicationId})
?

You can specify the Controller as another parameter of the Action helper:

@Html.Action("GetComments", "Home", new { id = ViewBag.loanApplicationId })

As for your text-area, just give this input a name that matches the post-action param:

@using Html.BeginForm("AddNewComment"))
{
@Html.Hidden("ApplicationId", ViewBag.loanApplicationId)
<div>
Add Comment: @Html.TextArea("NewComment")
</div>

<input type="submit" value="Submit" />
}

Action:

[HttpPost]
public ActionResult AddNewComment(int ApplicationId, string NewComment)
{
  // use ApplicationId to fetch the record
// add NewComment to the record

return redirectToAction("Index"); }

That’s a fairly simple solution.  If you have questions, ask away

Okay, I think I understand it now.  The only other question I have is if they should add a comment (remember they could be on any View page in the project), Once the comments pane is updated the user is has to return to the same view.  From what I have read
online, this should be some sort of "child action only".  Is that correct?

By the way, you are really awesome to have taken the time to help me!  I wish I could send you a gift!

So what you want to do is use an Ajax form, process the comment, then return a fresh instance of your Partial view back to the main View.  Let’s go through the whole thing, but with the ajax:

1) In your _Layout, you’ve got the Html.Action(…) helper.  We should wrap this in a <div> tag because we’re going to update this after our ajax-post

<div id="commentsDiv">
  @Html.Action("GetComments", "Home", new { id = ViewBag.loanApplicationId })
</div>

2) In your partial view, you’ve got your form that allows the user to add a comment.  We’re going to change this to an Ajax form

@using (Ajax.BeginForm("AddNewComment", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "commentsDiv" }))
{
  @Html.Hidden("AppId", ViewBag.loanApplicationId)
  <div>
    Add Comment: @Html.TextArea("NewComment")
  </div>

  <input type="submit" value="Submit" />
}

3) In the post-action, we process the new comment, then return our *UPDATED* _Comments partial view back to the view

[HttpPost]
public ActionResult AddNewComment(int AppId, string NewComment)
{
  // use ApplicationId to fetch the record
// add NewComment to the record

var comments = db.Comments.Where(c => c.ApplicationId == AppId).ToList();

return PartialView("_Comments", comments); }

And that’s it!  Now it’s important to note that you MUST have the unobtrusive-ajax scripts included in your View.  If you are unsure whether you have these, check your Scripts folder (download them from the NuGet manager if needed).

I received the following error when I tried to run this:

"Additional information: Error executing child request for handler ‘System.Web.Mvc.HttpHandlerUtil"

I tried to run in without the Id in the parameters and just hardcoded the ID in the method just for testing.  Here is what is in my _ApplicationLayout:

  <div id="PageClassDiv" class="@(ViewBag.PageClass) APPLICATION"><!-- page content container-->
        
        @Html.Partial("~/Views/Shared/_NavigationView.cshtml") <!-- Navigation Partial View -->
        @Html.Partial("~/Views/Shared/_SearchAccordionView.cshtml") <!-- Search Accordion Partial View -->

        <!-- All applications should have comments and sidebar ============================================================================================-->
        @Html.Partial("~/Views/Shared/_SideBarView.cshtml");
        @*@Html.Partial("~/Views/Shared/_CommentsView.cshtml");*@
        @Html.Action("GetComments", "LoanApplication")
        
        <!-- content ============================================================================================-->
        @if (angularEnabled)
        {
            <div class="container" ng-app="@angularAppName">@RenderBody()</div>
        }
        else
        {
            <div class="container">@RenderBody()</div>
        }
    </div><!-- end page content container-->

This is the CommentsView:

<span class="comments">
    <a id="right-menu" href="#right-menu" class="icon-comments"></a>
</span>
<span class="clear"></span>

<div id="sidr-right" class="sidr right">
    <header>
        <h4> Application Notes </h4>
        <a href="#" class="icon-print"></a>
        @using (@Html.BeginForm("Comment", "LoanApplication"))
        {
           @Html.TextArea("Comment")
        @*<textarea cols="100" rows="2" name="Comment" placeholder="Leave Comment ..."></textarea>*@
            <input value="Add Comment" type="submit" />
        }
    </header>

And this is what is in my controller:

  [HttpGet]
        [Route("GetComments")]
        public async Task<ActionResult> GetComments()
        {
            var loanApplicationServiceProxy = base.ServiceProvider.LoanApplicationServiceProxy;

            var comments = await loanApplicationServiceProxy.GetLoanApplicationCommentsByLoanApplicationIdAsync(loanApplicationId) ?? new List<LoanApplicationComment>();
            
            return PartialView("_CommentsView", comments);
        }


 [HttpPost]
        [Route("Comment")]
        public async Task<ActionResult> Comment(FormCollection form)
        {

            var loanApplicationServiceProxy = base.ServiceProvider.LoanApplicationServiceProxy;
            var userId = this.User.Identity.GetUserId();
            string comment = Request.Form["Comment"];
            var applicationComment = new LoanApplicationComment
            {
                Comment = comment,
                CreatedDate = DateTime.Now,
                LoanApplicationId = loanApplicationId,
                Id = Guid.NewGuid(),
                CreatedBy = Guid.Parse(userId)
            };
            await loanApplicationServiceProxy.PutLoanApplicationCommentAsync(applicationComment);

            var comments = loanApplicationServiceProxy.GetLoanApplicationCommentsByLoanApplicationIdAsync(loanApplicationId);

            return View(comments);
         
        }

The code in the Controller "GetComments" never gets hit.  The application throws an error as soon as I try to navigate to a View page that has the comments pane.

BeeDev

The code in the Controller "GetComments" never gets hit.

take off the [HttpGet] and [Route("GetComments")] annotations, and see if that works.

I was able to get it to hit the controller, but I can’t figure out how to actually display the comments.  I’m used to using @model.Comment, or something of the sort, but there is not model, so how do I specify the fields that I need to display?  I must display
the user name, date and time of comment, along with the comment.

This is going beyond the original scope of the question.  If I understand everything correctly, your _Comments partial view displays rows of comments that include user name, date & time of comment, and the comment.

The model for Comment may look something like this (I’m just guessing since you have not posted the actual model):

public class Comment
{
public int CommentId { get; set; } public string Comment { get; set; }
public string UserName { get; set; } public string CDate { get; set; }
public int App_ID { get; set; } }

The model includes a primary index key (CommentId), the other required fields, and also a foreign key reference (App_ID)

The _Comment partial view may then look like this:

@model IEnumerable<AppName.Models.Comment>

<h2>Submit Comment</h2>

@using (Ajax.BeginForm("AddNewComment", "LoanApplication", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "commentsDiv" }))
{
  @Html.Hidden("AppID", ViewBag.loanApplicationId)
  <div>
    Comment: @Html.TextArea("NewComment")
  </div>

  <input type="submit" value="Submit" />
}

<h2>Comments</h2>

@foreach (var item in Model)
{
  <div>
    <dl class="dl-horizontal">
      <dt>Username</dt>
      <dd>@Html.DisplayFor(modelItem => item.UserName)</dd>

      <dt>Date</dt>
      <dd>@Html.DisplayFor(modelItem => item.CDate)</dd>

      <dt>Comment</dt>
      <dd>@Html.DisplayFor(modelItem => item.Comment)</dd>
    </dl>
  </div>
}

To explain, our @model is a LIST of comments that will be passed to the partial view.  At the top I’ve included the AJAX form, which allows a user to submit their comment.  Below the form is the Comments section, which loops through each comment, displaying
the User, the Date, and the Comment (I used DL formatting but you can use TABLE or DIV, etc).  Now when the form posts and finishes processing, we’ll be returning a fresh _Comments partial view, which will replace the old one.  We use "UpdateTargetId" to specify
where to update.

Your AJAX post-action in your "LoanApplication" controller:

[HttpPost]
public ActionResult AddNewComment(int AppID, string NewComment)
{
  // create new comment object
  var comment = new Comment();
  comment.Comment = NewComment;
  comment.UserName = User.Identity.Name;
  comment.CDate = DateTime.Now;
  comment.App_ID = AppID;

  // add comment to db
  db.Comments.Add(comment);
  db.SaveChanges();

// query new comments list and return to partial view var comments = db.Comments.Where(c => c.App_ID == AppID).ToList(); return PartialView("_Comments", comments); }

I’ve commented this for explanation.

Your _Layout view now only needs to have the initial Action helper inside a named DIV

<div id="commentsDiv">
  @Html.Action("GetComments", "LoanApplication", new { id = ViewBag.loanApplicationId })
</div>

As said earlier, once the AJAX form posts, a new version of _Comments partial view will replace the contents of "commentsDiv".

Lastly, the "GetComments" action (in the LoanApplication controller):

public ActionResult GetComments(int id)
{
  var comments = db.Comments.Where(App_ID == id).ToList();

  return PartialView("_Comments", comments);
}

And that’s it.  There’s the entire solution…  If all of this works for you, please take a moment to mark all my responses as answers, as they all answer each of your subsequent questions.  Thanks.

Okay, I figured out that I can put a model in the _CommentsView.cshtml since it is being rendered with an @Html.Action.  Thanks for ALL of your help!  You are awesome!!!

how to make working my query

Hi, i got 2 link on created with  

<a href="@Url.RouteUrl("

and the other with

 <li>@Html.RouteLink(

both give me the right routed link :

first link

http://localhost:57959/Magazine/Index/1/styles-inspirations

second link

http://localhost:57959/Magazine/Index/1/styles-inspirations/2/fetes-occasions

but only the second works with the query, why?

if (menuid.HasValue)
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

            if (submenuid.HasValue)
            {
                magazines = magazines.Where(r => r.ParentSubMenuMag.SubMenuId.Equals(submenuid.Value));
            }

how to make working the first link with my search?

Hi graphic,

Thanks for your post.

grafic.web

<a href="@Url.RouteUrl("

You can use it directly,like this:

    @Url.RouteUrl(...);

More information:

http://www.patridgedev.com/2011/08/22/subtleties-with-using-url-routeurl-to-get-fully-qualified-urls/

Hope it can be helpful.

Best Regards,

Eileen

grafic.web

<a href="@Url.RouteUrl("

@Html.RouteUrl returns a url string and it does not render anchor tag

grafic.web

<li>@Html.RouteLink(

@Html.RouteLink renders a anchor tag with url

Hi,

how should i modify my code of the query to make working this with <a href="@Url.RouteUrl(" ?

if (menuid.HasValue)
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

with this :

<li>@Html.RouteLink(

my second query works well :


            if (submenuid.HasValue)
            {
                magazines = magazines.Where(r => r.ParentSubMenuMag.SubMenuId.Equals(submenuid.Value));
            }

In fact  the problem is that with <li>@Html.RouteLink( the query above works and not wiht
<a href="@Url.RouteUrl("

How to modifiy this query?

post your routelink and routeurl completely to know how u used

Hi,

here my RouteConfig.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace HairCollection3
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}/{title}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optional }
            );

            //localhost/Magazine/menuid/menuname/submenuid/submenuname/ID
            routes.MapRoute(
            name: "MagazineRoute",
            url: "{controller}/{action}/{menuid}/{menuname}/{submenuid}/{submenuname}/{id}",
            defaults: new { controller = "Magazine", action = "Index", menuid = UrlParameter.Optional, menuname = UrlParameter.Optional, submenuid = UrlParameter.Optional, submenuname = UrlParameter.Optional, id = UrlParameter.Optional }
           );


        }
    }
}

And the link

first link (SEARCH QUERY does not work)

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>   

second link (SEARCH QUERY works wel)l :

<li>@Html.RouteLink(SubMenuName, "MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly(), submenuid = submenu.SubMenuId, submenuname = SubMenuName.URLFriendly(), })</li>

This is the SEARCH QUERY

if (menuid.HasValue) // First link
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

            if (submenuid.HasValue)  //second link
            {
                magazines = magazines.Where(r => r.ParentSubMenuMag.SubMenuId.Equals(submenuid.Value));
            }

grafic.web

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>

I do not find any issue with the above

is the link only for GET or also for POST

Hi, me too, but i don’t know why it does not work with this query :

if (menuid.HasValue)
             {
               magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

And the second link, works well with the other query, in fact if i click on it i see only the list of the
ParentSubMenuMag.SubMenuId.Equals(submenuid.Value

How should i change this query to work with this link?

<div>

The problem is that if i change my link :

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>    

like this :

@Html.RouteLink(MenuName, "MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })</li>

it works perfectly… so the problem, i guess is in the  @Url.RouteUrl(", becaus if i use the
@Html.RouteLink( the query can find the menuid.HasValue

How comes?

</div>

My query SQL DOES NOT WORK

Hi, i did this simple query, where i show in my list of magazine only the one belonging to the menuid choosen in the link but it doe not work

Query :

 //I  think you can actually drop the Likes include as it will be included with the Likes.Select include, so maybe try this (although if it doesn't work, use the first example which should):
            var magazines = db.Magazines.Include(m => m.ParentMenuMag).Include(m => m.ParentSubMenuMag).Include(m => m.Likes.Select(l => l.User)) as IQueryable<Magazine>;

            if (menuid.HasValue)
            {
                magazines = magazines.Where(r => r.ParentMenuMag.MenuId.Equals(menuid.Value));
            }

Link

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>    

Result link

<a href="/Magazine/Index/1/styles-inspirations" title="Styles &amp; Inspirations">Styles &amp; Inspirations<i class="fa fa-angle-down"></i></a> 

RouteConfig.cs

 //localhost/Magazine/menuid/menuname/submenuid/submenuname/ID
            routes.MapRoute(
            name: "MagazineRoute",
            url: "{controller}/{action}/{menuid}/{menuname}/{submenuid}/{submenuname}/{id}",
            defaults: new { controller = "Magazine", action = "Index", menuid = UrlParameter.Optional, menuname = UrlParameter.Optional, submenuid = UrlParameter.Optional, submenuname = UrlParameter.Optional, id = UrlParameter.Optional }
           );

What is wrong?

You question was not clear for me. I didn’t understand the relation between the hyperlink and the query.

Hi,

grafic.web

does not work

It’s best to always tell what is the error or behavior you see. For example it can happen that the problem is unrelated to what you shown in which case someone will waste time in trying to find what is the error you have (that is an information that you
know already) rather than on how to solve your issue.

HI, no error.. just i see all the item of the list and not only the onewith the idmenu choose…

in fact the query  has not be called.. why? th idmenu exist

Even the behavior is helpfull. So for now it would seem that menuid.HasValue is false. Please use the VS debugger to see if this is the case. From what you
shown I don’t see why.

menuid is part of your action signature I suppose? (and so I could’t imagine that without knowing what actually happens).

Try /Magazine/Index/1/a/2/b/3 in your browser and see in the VS debugger if the various values are correctly populated etc…

The problem is that if i change my link :

<a href="@Url.RouteUrl("MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })" title="@MenuName">@MenuName<i class="fa fa-angle-down"></i></a>    

like this :

@Html.RouteLink(MenuName, "MagazineRoute", new { controller = "Magazine", menuid = menu.MenuId, menuname = MenuName.URLFriendly() })</li>

it works perfectly… so the problem, i guess is in the  @Url.RouteUrl(", becaus if i use the
@Html.RouteLink( the query can find the menuid.HasValue

How comes?

What if using "view source" in both cases to see which HTML markup is generated and see how they differ?

[RESOLVED]MVC 2 TELERIK

Dear Experts,

I am using the MVC2 WEB application .
I have downloaded dll from this site http://simple-telerik-extensions.googlecode.com/svn-history/r14/trunk/telerik/Binaries/Mvc2/

I am using the following code in my view
   <%
        Html.Telerik().ComboBox()
            .Name("MenuIDs")
            
        .Render();       

                 %>
i am getting following error please help me
 ‘Telerik.Web.Mvc.UI.ViewComponentFactory’ does not contain a definition for 
‘ComboBox’ and no extension method ‘ComboBox’ accepting a first argument of type 
‘Telerik.Web.Mvc.UI.ViewComponentFactory’ could be found (are you missing a 
using directive or an assembly reference?)

Do you have the appropriate @using statement at the top of the view?  Or in the web.config file?  I’m sure the documentation will explain what you need for the methods to be found.

Any body who have used Telerik with MVC 2 PLEASE HELP ME

You should be asking Kendo about this, you’ll get a better response.  Have you installed it properly?

http://docs.telerik.com/kendo-ui/aspnet-mvc/introduction

Have you looked at the troubleshooting section that shows you the web.config changes I have asked if you have made?

http://docs.telerik.com/kendo-ui/aspnet-mvc/troubleshooting

You’ll get much better support from Kendo and their forum, but if you want to ask questions on a general asp.net forum then saying you’ve downloaded a dll and it doesn’t work won’t give us enough info to go on.  At least start with the installation instructions
and the trouble-shooting pages above.

It sounds like you are simply missing the appropriate References within your project to the Telerik extensions. In addition, you’ll likely need to include references to the appropriate libraries within your web.config similar to the example shown below :

<pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <!-- Notice the Telerik.Web.Mvc.UI Reference -->
        <add namespace="Telerik.Web.Mvc.UI" />
      </namespaces>
</pages>

This should include the needed reference within all of your Views so that you can use the helpers as necessary. I also agree with Aidy regarding using Telerik / Kendo’s support in the future. In my experiences they have always been extremely helpful and
quite quick to respond to any issues like this (generally searching through
their forums
can be a life-saver for commonly encountered issues
).

[RESOLVED]Please confirm this resolution for a security exception due to the trust level when hosting MVC5 on GoDaddy

Hello,

VS2013 update 3, MVC5

When I deployed without modification the standard MVC5 template to GoDaddy I immediately received a security exception.  The security exception basically indicated the environment’s security policy didn’t allow "…ReflectionPermission", which MVC5 evidently
wants to use.

My initial research revealed a lot of posts stating many hosting providers only offer "medium trust" and that would be a show stopper for an MVC5 site.  I eventually found a Stack Overflow post where an individual using GoDaddy simply added the following
line to web.config:

  <system.web>
    ...
    <trust level="Full" />
  </system.web>

This worked, at least for now.  So these are my questions, and if there seem to be other appropriate comments to add, please do so.

1) Is it true that without "full trust" MVC5 cannot effectively be used?

2) Were most of the posts suggesting many hosting providers wouldn’t provide full trust simply a reflection of a changing industry environment?

3) Can we reasonably expect that higher tier hosting providers will support trust levels required for effective MVC5 use?

4) Since I was able to add <"trust level = "Full"/> without getting an error from the hosting provider AND the MVC5 site loaded OK (remember it’s just the default template), can I reasonably expect I won’t run into trust level problems going forward?

I will add for others who may read this thread, I had zero problems deploying to Azure.

Best Regards,

Alan

 

Hi Alan,

Most of hosting provider offer FULL Trust hosting now. As I know, godaddy doesnt offer for Full Trust. You may check it with them. For above issue, it is truly the permission issue. If you require full trust hosting, you can find it on
Microsoft spotlight site, for example asphostportal

If the target is shared hosting, it will be safer to believe in medium trust.

http://www.4guysfromrolla.com/articles/100307-1.aspx

Hi cnranasinghe and Carl,

Carl, I will reach out to GoDaddy.  I am confused because I added the "Full" trust line in my web.config and the hosting server didn’t complain.  I assumed that meant I have "Full" trust.  Maybe not.  I’ll probably post an addendum here after I find out. 
It is odd that the MVC5 site didn’t run without the explicit "Full" trust line, because the spec says the trust level defaults to "Full".  So if I added "Full" to my web.config, I was just defining what already was the default.  Why would that have been necessary?

cnranasinghe, That was a great link to understand the implications.  Thanks!  Can you confirm what I think I read?

It seems as though MVC5 may run in "Medium" trust, but certain methods may not operate if they or their class require "Full", and the only way to really know that is to set "Medium" trust in the development environment and see what works?  Or is there an
easier way to know?

Thanks,

Best Regards,

Alan

Hi Carl,

Thought you and others would be interested to know that GoDaddy does in fact support Full Trust on their shared hosting servers.  Historically this has changed back and forth since ASP.NET 2.0, so that probably explains why there is some confusion over what
is available with GoDaddy.  Additionally, not every one of their support agents is fully aware of this nuance, but it is available.

There are 2 ways to engage Full Trust on GoDaddy.  Web.config can be modified as shown above.  Without that line in web.config, the default of Medium Trust will be applied. 

Alternatively, there is a webpage for each website that permits manual setting for a variety of ASP.NET parameters (at the time of writing this post, the User Interface doesn’t default to show the menus/additional webpages and you have to expand the menu
panel by clicking on the ‘Show More’ tab).   Once on the ASP.NET Settings Page there is a drop down box (currently called Code Access Security) that allows setting the Trust for that particular website (This is where the default Trust setting is set, but only
for that website).  If Full Trust is selected there, then the line in web.config will not be needed.  Interestingly, if web.config has that line, then the web page will change to reflect what’s in web.config.

Best Regards,

Alan