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 3 posts 73 karma points
    Aug 15, 2019 @ 06:42
    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.

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Aug 16, 2019 @ 06:51
    Shaishav Karnani from digitallymedia.com
    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 3 posts 73 karma points
    Aug 18, 2019 @ 10:22
    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