Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "Garysund"

Hi There

This may be a very noob question but I am struggling to implement a standard @Html.DropDownListFor. Does anybody have ant examples or can show me how to implement this.

Modal Code

<label for="ParentId">@L("Parent Category")</label>
            @Html.DropDownList("ParentId", Model.CategoryList.Select(i => i.ToSelectListItem()), new { @class = "form-control edited" })

Controller

public async Task<PartialViewResult> CreateOrEditModal(int? id)
        {
            var output = await _categoryAppService.GetCategoryForEdit(new NullableIdDto { Id = id });
            var viewModel = new CreateOrEditCategoryModalViewModel(output);

            return PartialView("_CreateOrEditModal", viewModel);
        }

APP Service

public async Task<GetCategoryForEditOutput> GetCategoryForEdit(NullableIdDto input)
    {
        var categorylist = _categoryRepository.GetAll().ToList();
        CategoryEditDto categoryEditDto;

        if (input.Id.HasValue) //Editing existing role?
        {
            var category = await _categoryRepository.GetAsync(input.Id.Value);
            categoryEditDto = category.MapTo<CategoryEditDto>();
        }
        else
        {
            categoryEditDto = new CategoryEditDto();
        }

        return new GetCategoryForEditOutput
        {
            Category = categoryEditDto,
            CategoryList = categorylist.
           
        };
    }

DTO

public class GetCategoryForEditOutput
    {
        public CategoryEditDto Category { get; set; }

        public List<ComboboxItemDto> CategoryList { get; set; }

       
    }

I am getting the following error when query a recursive entity lookup.

{"message":"An error has occurred.","exceptionMessage":"There is an action GetCategories defined for api controller app/category but with a different HTTP Verb. Request verb is GET. It should be Post","exceptionType":"System.Web.HttpException","stackTrace":" at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.GetActionDescriptorByActionName(HttpControllerContext controllerContext, DynamicApiControllerInfo controllerInfo, String actionName)\r\n at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.DynamicApiController1Proxy_5.ExecuteAsync_callback(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.Invocations.ApiController_ExecuteAsync_5.InvokeMethodOnTarget()\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Abp.WebApi.Controllers.Dynamic.Interceptors.AbpDynamicApiControllerInterceptor1.Intercept(IInvocation invocation)\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Castle.Proxies.DynamicApiController`1Proxy_5.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

The error only occurs after I added the first entry that has a ParentId

Model

[Table("Categories")]
     public class Category : FullAuditedEntity
     {
        [Required]
        public string Name { get; set; }
        [Required]
        public string SharepointMapping { get; set; }
        public int? ParentId { get; set; }
        public Category Parent { get; set; }
       public List&lt;Category&gt; Children { get; set; }
     }

CategoryAppService

public ListResultDto&lt;CategoryListDto&gt; GetCategories(GetCategoriesInput input)
{
    var categories = _categoryRepository
        .GetAll()
        .WhereIf(
            !input.Filter.IsNullOrEmpty(),
            p => p.Name.Contains(input.Filter) 
        )
        .OrderBy(p => p.Name)
        .ToList();

    return new ListResultDto&lt;CategoryListDto&gt;(categories.MapTo&lt;List&lt;CategoryListDto&gt;>());
}

CategoryListDto

[AutoMapFrom(typeof(Category))]
public class CategoryListDto : FullAuditedEntityDto
{
    public string Name { get; set; }
    public string SharepointMapping { get; set; }
    public int? ParentId { get; set; }
    public virtual Category Parent { get; set; }

}

Thanks I am pulling my hair out on this one

Showing 11 to 12 of 12 entries