asked    Maxwell     2018-10-12       asp.net-mvc       16 view        1 Answer

[SOLVED] Umbraco - custom model causing problems?

In a vanilla Umbraco project, i am importing a vanilla MVC app. I am currently beeing held up, by this error:

Cannot bind source type eParser.Model.MyModel to model type MyNamespace.Controllers.ViewModel`1[[eParser.Model.MyModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

This is my code:

Local project

namespace MyNamespace.Controllers
{
    public class MyOutputController : RenderMvcController
    {
        private static Parser _parser;

        public MyOutputController()
        {
            _parser = new Parser(@"localfile.txt");
        }

        public override ActionResult Index(RenderModel model)
        {
        var settings = new RPSettings();
        var wsParser = _parser.GetwsParser();
            var result = wsParser.GetDataAsMyModel(settings);
        return View("MyView", result);
    }
     }

    public class ViewModel<TModel> : RenderModel
    {
        public ViewModel(RenderModel model) : base(model.Content, model.CurrentCulture) { }

        public TModel MyModel { get; set; }
    }
}

External project

namespace eParser
{
    public class wsParser
    {
    public MyModel GetDataAsMyModel(RPSettings settings)
        {
            var model = new MyModel();
        return model;
    }
    }
}

namespace eParser.Model
{
    public class MyModel
    {
        public string Name { get; set; }
        public string Value1 { get; set; }
        public bool IsValid { get; set; }
    }
}

Template

@using MyNamespace.Controllers
@using OtherNamespace.Models
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ViewModel<MyModel>>
@{
    Layout = "/Views/Shared/_Layout.cshtml"; //Just <html> and very basic - no code
    var addModel = new AddListViewModel
    {
        MyType = MyType.Value1,
        MyModel = Model
    };
}

<h1>@Model.Name</h1>


namespace OtherNamespace.Models
{
    public class AddListViewModel
    {
        public string ValueName { get; set; }
        public MyType MyType { get; set; }
        public ViewModel<MyModel> MyModel { get; set; }
    }
}

Any ideas what i could do to fix it?

  1 Answer  

        answered    Lydia     2018-10-12      

Your Index method is wrong - you are passing in your model to the view but you should be passing your view model instead.

It should be:

public override ActionResult Index(RenderModel model)
{
    var settings = new RPSettings();
    var wsParser = _parser.GetwsParser();
    var result = wsParser.GetDataAsMyModel(settings);

    var viewModel = new ViewModel<MyModel>(model);
    viewModel.MyModel = result;

    return View("MyView", viewModel );
}




Your Answer





 2018-10-12         Katherine

Refreshing the page even if error message is shown

I'm using umbraco CMS and have a problem with my form.I've added error messagges if some of the fields are empty.If you click on "submit" the page is refreshing, and you need to scroll down again to the form section in order to view the error messages.I did a lot of changes in the form section (design) but can't find a solution to the problem.Has anyone had the same issue? Are you using the new UmbracoForms implementation? This sounds to me like a script or style issue. You should track when the user has submitted the form and after the submission (if there are errors pr...
 forms                     1 answers                     96 view
 2018-10-12         Vivien

What port does Courier for Umbraco use?

I have had a few problems setting up Courier for umbraco (v7).After a bit of trial an error I have discovered the destination server has all its ports blocked other than 80.Does anyone know what port I need to open up to get it to work? I'm pretty sure Courier just runs over port 80, as it's all web based. [XXX]
 umbraco                     1 answers                     97 view
 2018-10-12         Joan

How to check which html tag is the title field using in umbraco

Is there a way to check on backend which tag user is using for title field on any content page. e.g. h1 or h2 in Umbraco Umbraco doesn't have a specific template that is used for all sites built using Umbraco. As such, its difficult to answer your question directly. Here are some ways you could find out:In your browser, right-click and either "View Source" or "Inspect Element" and find the title that you are looking to get more information for. If you add something unique (a * or some character) that may help you to find it. The text of the title should have the h1 o...
 jquery                     1 answers                     98 view