November Happy Hour will be moved to Thursday December 5th.

Model binding not working in add-on

Vote:
 

Hi,

I am writing a custom episerver plugin with MVC and Razor.

I have a Controller, decorated with a GuiPlugin attribute. I have a Index, Delete and Create action. The index action is rendered correctly when I browse to it in EPiServer. However, when I want for example call the Delete action I want to add a id as routevalue. Somehow the id is null when I use it in the parameters of my Delete action. Apparently the modelbinding is not working correctly.

Should I build a new modelbinder for this or is my configuration faulty? I am hoping for the last option.

 

------------------

Model.config:

<?xml version="1.0" encoding="utf-8"?>
<module loadLocalBin="false">
    <assemblies>
        <add assembly="eFocus.Poliservice.Framework.Websites.Poliservice" />
    </assemblies>

    <routes>
        <route url="{moduleArea}/{controller}/{action}">
            <defaults>
                <add key="moduleArea" value="eFocus.Poliservice.Framework.Websites.Poliservice" />
                <add key="controller" value="" />
                <add key="action" value="Index" />
            </defaults>
        </route>
    </routes>
</module>

    

My Controller:

    [GuiPlugIn(
        Area = PlugInArea.AdminMenu, 
        SortIndex = 1,
        UrlFromModuleFolder = "AccountsPlugin",
        DisplayName = "Manage website accounts",
        RequiredAccess = AccessLevel.Administer)]
    public class AccountsPluginController : Controller
    {
        private readonly IAccountManager accountManager;

        public AccountsPluginController()
        {
            accountManager = PlatformContext.Current.Container.Resolve<IAccountManager>();
        }

        public ActionResult Index(int? page)
        {
            var pageNumber = page ?? 1;
            int totalUsers;
            IPagedList<MembershipUser> users = this.accountManager.GetAllAccounts(out totalUsers).ToPagedList(pageNumber, 25);

            return View(users);
        }

        public ActionResult Delete(string id)
        {
            //do stuff

            return RedirectToActionPermanent("Index");
        }

        public ActionResult Create()
        {
            return View();
        }
    }

    

#82932
Mar 21, 2014 14:21
Vote:
 

ActionLink:

@Html.ActionLink("Delete", "Delete", "AccountsPlugin", new { id = item.UserId })

    

#82933
Edited, Mar 21, 2014 14:23
Vote:
 

Ok, i found the solution:

@Html.ActionLink("Delete", "Delete", "AccountsPlugin", new { id = item.AnvaId }, null)

    

and of course you must define it in your route. Not in routeconfig but in module.config:

 

        <route url="{moduleArea}/{controller}/{action}/{id}">
            <defaults>
                <add key="moduleArea" value="eFocus.Poliservice.Framework.Websites.Poliservice" />
                <add key="controller" value="" />
                <add key="action" value="Index" />
                <add key="id" value="" />
            </defaults>
        </route>

    

#82943
Mar 21, 2014 16:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.