Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Haris Tasawar 2 posts 72 karma points
    5 days ago
    Haris Tasawar
    0

    Hi all,

    As i am fairly new to Umbraco, i seem to be having issues regarding route hijacking. I keep getting the below error when i am trying to achieve this:

    Cannot bind source type Umbraco.Web.Models.ContentModel to model type Test.Company.

    So, below are the details regarding my code:

    Model(Company.cs):

       public partial class Company
    {  //  public int CompanyID { get; set; }
        public string CompanyNameEnglish { get; set; }}
    

    Controller(companyDashboardController.cs):

    public class companyDashboardController : RenderMvcController
    {
    
    
        public ActionResult CompanyNavRender()
        {
            Company model = new Company();
            return PartialView("CompanyNavBar", model);
        }
    
        [HttpPost]
        public ActionResult Companydashboardload(string Compname)
        {
            TestEntities db = new TestEntities();
    
    
            string username = System.Web.HttpContext.Current.Session["UserName"].ToString();
            var obj = db.Companies.Where(a => a.CompanyNameEnglish.Equals(Compname));
            if (obj != null)
            {
    
    
                return View("~/Views/companyDashboard.cshtml", obj);
    
    
                // Session["UserID"] = obj.RegistrationID.ToString();
                // Session["UserName"] = obj.UserName.ToString();
                // in//t thankYouPageId = Int32.Parse(CurrentPage.GetProperty("taxify-registration"));
                //return RedirectToUmbracoPage(1168);
                // return RedirectToUmbracoPage("/test-registration");
            }
    
            return View("~/Views/companyDashboard.cshtml", obj);
    
    
    
        }
    
    
    }
    

    }

    My View(companyDashboard.cshtml):

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Company>
    @{
     Layout = null;
      }
    
       <section class="page_toplogo ls c-my-15 breadcrumbs">
                <div class="container-fluid">
    
                    <div class="row align-items-center">
    
    
    
                        <div class="col-lg-4 text-center text-lg-left">
                            @*<a href="./" class="logo text-center">
                <img src="~/images/logo-dark.png" alt="">
            </a>*@
    
                        </div>
    
    
                        @Html.Action("CompanyNavRender", "companyDashboard");
    
    
                    </div>
                </div>
    
    
            </section>
    

    I have included the part which i think is causing the error to be generated.

    Also, i have a document type of the same name (i.e companyDashboard) in Umbraco as well.

    Can anyone please help me with this issue?

    Thanks, Harry.

  • DigitallyMedia - Umbraco Specialist 87 posts 356 karma points
    4 days ago
    DigitallyMedia - Umbraco Specialist
    0

    You need to first general class using model builder. It will generate class companyDashboard.cs

    public class CompanyDashboardController : Umbraco.Web.Mvc.RenderMvcController { public override ActionResult Index(ContentModel model) { // Do some stuff here, then return the base method // model.Content will have iPublishedContent from companyDashboard return base.Index(model); } }

  • Haris Tasawar 2 posts 72 karma points
    2 days ago
    Haris Tasawar
    0

    Hi Digitally,

    Thanks for the tip but i am actually not using the model builder , i am not sure if it`s support on V8 of umbraco, i am actually using Entity Framework for MVC so i am not sure if i can use the model builder package to do this? is it possible to use both for my Application?

    Thanks, Harry.

Please Sign in or register to post replies

Write your reply to:

Draft