w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[X]', but this dictionary requires a model item of type 'X'
Take this at face value - yours is not unique. Your problem is you are passing an array of user to a controller action that expects a user. You need to post your HTML but it is probably something like @model List user or something instead of a single user. If your model represents a single user then pass that to the controller. If opposite, do opposite, If you want to pass a list to the controller use list users edit make your razor syntax @model Mike.Models.User

Categories : Asp Net Mvc

In Umbraco 6.1.1 MVC 4, how can I do a form post back to a surface controller using a model that inherits from Umbraco's RenderModel?
Ok, I've had no responses to this question but am now in a position to answer it myself. Maybe it was a fundamental oversight, but not that obvious imho, and information on the Umbraco forum etc about inheriting from RenderModel is fairly limited. Essentially the answer, as was my first instinct, is to solve the original exception "No parameterless constructor defined for this object" by providing a paramaterless constructor. The difficulty is working out what to put inside the parameterless constructor for my model, since it inherits from the Umbraco RenderModel which requires an IPublishedContent instance passed to it's constructor. Luckily while browsing around I happened across this post on the Umbraco forum: http://our.umbraco.org/forum/developers/api-questions/40754-Getting-Curre

Categories : Asp Net Mvc

Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines
If you are trying to host the blogengine site within a virtual directory of the Umbraco site, then you will have to amend the blogengine web.config to "remove" all the Umbraco-specific handlers and modules, as these will be inherited by the blogengine application, causing this exception because the application can't find the relevant DLLs in its bin folder. I recently had a similar problem and I have posted the web.config I used in the virtual directory below. Mine was a very simple web application, so obviously this will not work by itself in your blogengine app. You will need to add the relevant parts into your web.config file. Also, this was for a v6 Umbraco install in IIS7.5, so you may have to experiment a little. <?xml version="1.0"?> <configuration> <configSecti

Categories : Iis

Issue with Dictionary type, If gived a specific text then get the equivalent dictionary key or dictionary value?
If this were my application, I would change the UI element to a datagridview so that I could bind a collection containing a custom class and just hide or show the appropriate columns as needed. This approach will allow you to easily add additional property columns in the future without worrying about the problems you are currently facing. It would also allow you to extend the UI to other platforms (mobile, web) without a lot of hard-coded information in the UI. For example, I would create the following class and collection to hold info about the files: Public Class FileDetails Public Property Index As Integer Public Property Description As String = String.Empty Public Property FullFileName As String = String.Empty Public ReadOnly Property FileName As String Get

Categories : Dotnet

Unique Name for Navigation Item in Umbraco
Okay, I never understood what I was reading when I kept seeing articles about umbracoUrlName, but I finally figured it out. Basically, I keep the code above the same, but I just changed the alias from menuItemName to umbracoUrlName (it is a textstring) and whatever I put in there is what the URL is for that page! Geeze, I feel silly now, but at least it is working!

Categories : Xslt

Select "umbraco item" using razor
You cannot use server tags inside your razor template. tags like: <umbraco:Item field="field_1" runat="server" /> But you can call @Model.field_1 Final version should look like that: @if (condition) { @Model.field_1 } else { @Model.field_2 } Check this post about razor macros in umbraco: http://www.diplo.co.uk/blog/2011/6/17/using-razor-in-umbraco-47.aspx

Categories : Asp Net Mvc

How to create Inherited Member-Type in Umbraco 6.X?
Member objects do not quite work like that in Umbraco. You can not inherited member objects in the same way that you can inherit document types or media types. I would simply create two independent user types here with the properties you require. If you desperately want the inheritance, you could implement your own membership provider or extension to the API, but even then the inheritance would not be visible in Umbraco, only at the code level. In Umbraco the member types would still appear as independent objects. So it seems like little gain.

Categories : Asp Net

Umbraco MVC Implementation - View does not depend on Umbraco implementations
No you can't. Simply because all requests pass through a single action. In order to retrieve a path to a CMS-managed page, you need to use the node/content traversal the @Model provides. See here for more details on this. Edit To clarify, the author of the article is suggesting that the Umbraco implementation should be more in line with a traditional MVC implementation with little or no logic in the views. Therefore, any querying of node data should happen prior to the view (e.g. in the Mappers). So this is where you would have to retrieve the links. Umbraco's default MVC implementation forces all requests to go via a single action on a single controller. The author's implementation allows the requests to be shared across one controller per document type - which is better IMO. But it st

Categories : Asp Net Mvc

HTTP GET to return custom model with data from external database with Umbraco MVC Surface Controller
There are a lot of questions about this and the best place to look for an authoritative approach is the Umbraco MVC documentation. However, yes you will find, if you use Html.BeginUmbracoForm(...) you will be forced into a HttpPost action. With this kind of functionality (a search form), I usually build the form manually with a GET method and have it submit a querystring to a specific node URL. <form action="@Model.Content.Url"> ... </form> On that page I include an @Html.Action("SearchResults", "TyresSearch") which itself has a model that maps to the keys in the querystring: [ChildAction] public ActionResult(TyreSearchModel model){ // Find results TyreSearchResultModel results = new Wheels.BDL.TyreBDL().GetAllTyres(); // Filter results based on submitted mo

Categories : Asp Net Mvc

How can I cast a subset of a dictionary to a type derived from Dictionary<>
You get an invalid cast exception because the result of ToDictionary is not MyDict. In order to fix this problem, add a constructor to MyDict that takes an IDictionary<string,A>, and return the result of calling that constructor from your GetSubSet method: public class MyDict : Dictionary<string, A> { public MyDict() { // Perform the default initialization here ... } public MyDict(IDictionary<string,A> dict) { // Initialize with data from the dict ... } } ... public MyDict GetSubSet(int testVal) { var ret = dict.Where(e => e.Value.aValue == testVal). ToDictionary(k => k.Key, k => k.Value); return new MyDict(ret); }

Categories : C#

Umbraco MediaService / Umbraco MediaItem not saving
To Save media, I found this method with MediaService. However, I think it's possible another method more refined [HttpPost] public JsonResult Upload(HttpPostedFileBase file) { IMedia mimage; // Create the media item mimage = _mediaService.CreateMedia(file.FileName, <parentId>, Constants.Conventions.MediaTypes.Image); mimage.SetValue(Constants.Conventions.Media.File, file); _mediaService.Save(mimage); return Json(new { success = true}); }

Categories : C#

Umbraco - error when using umbraco.library:NiceUrl(...)
Ok I found a solution: I added an extra check to this part: <!-- Return the url --> <xsl:if test="$i = $max"> <xsl:if test="$id != '' "> <xsl:value-of select="umbraco.library:NiceUrl($id)" /> </xsl:if> </xsl:if> this fixed my problem.

Categories : Xslt

"The type IUnitOfWork does not have an accessible constructor" with Umbraco 6.1, UmbracoApiController (Web API) & Dependency Injection (Unity)
In case you haven't found a solution to your problem? Download this nuget package and right after building your unity container: GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(Bootstrapper.Container); Notice the namespace which is different than Unity.Mvc4.UnityDependencyResolver.

Categories : Asp Net Web Api

Ruby on Rails form requires another model to have certain entries
If I am reading this correctly you want to redirect them to a different page to create the service if it's not already in the database? I'm not sure how you have setup your routes, but if you are using resources :services You could do something like redirect_to new_service_url inside of the if instead of your render statement. more on redirecting in rails

Categories : Ruby On Rails

Linq: Non-static-methods-requires-a-target with select new {model}
You are getting a null reference exception. It is called a non-static target exception since LINQ uses reflection in the backend to do its thing. CurrentUser = b.UserProfile == null ? null : b.UserProfile, BetaId = b.Id == null ? 0 : b.Id, Is causing it, you need to do CurrentUser = b == null ? null : b.UserProfile, BetaId = b == null ? 0 : b.Id, Since the default value of a reference type is null.

Categories : Asp Net Mvc

Client Object Model call context.executeQueryAsync: After adding an item to a list, cant open the new item until the onQuerySucceeded completes?
Update: The Edit Task dialog now opens the item as expected. I am not sure why. I may have changed a list setting related to email notifications on change of assignment. HTH /bac

Categories : Javascript

error "C++ requires a type specifier for all declarations"
You could simply define function inside template class template <class T> class sequence { //... sequence() : used(0) // define function inside template class. { } //... } Or you need to add template <class T> and <T> before every function defined outside the template declaration: template <class T> sequence<T>::sequence( ) ^^^^^^^^^^^ { used = 0; } template <class value_type> void sequence<T>::attach(value_type entry) ^^^^^^^^^^^ { data[used++] = entry; } template <class T> typename sequence<T>::value_type sequence<T>::current( ) ^^^^^^^^ // 1. value_type comes from sequence template, so you need to specify sequence<T> ^^^^^^^ // 2. sequence<T>::value_type type depends on

Categories : C++

cakephp - how to get the data from a model->model->model type relationship
The way you have it now you are basically just calling the PaypalTransaction model and request its find to return you all transactions in the last day. $this->FirstModel->SecondModel->ThirdModel doesn't mean to connect results from the first model to the second and then to the third, it's only a way to help you load the linked model instead of using $this->loadModel('ThirdModel') to load it. So you still need to place conditions according to what you want to do. For example, if it was just one model linked (assuming $this->Booking is set to a record) you could do: $this->Booking->PaypalTransaction->find('all', array( 'conditions' => array( 'PaypalTransaction.created >' => $oneDayAgo, 'PaypalTransaction.booking_id => $this->Booking-

Categories : PHP

Dictionary.Item in C#
Dictionary<string, decimal> dictionary = null; Person oPerson = null; string key = "SomeValue"; if (dictionary.ContainsKey(key)) { oPerson = dictionary[key]; } Dictionary<string, decimal> dictionary = null; Person oPerson = null; string key = "SomeValue"; if (dictionary.ContainsKey(key)) { oPerson = dictionary[key]; }

Categories : C#

how do I use after_save for a model as well as for all its associated models?
You can use an ActiveRecord::Observer to watch for changes on the association models and then trigger a callback on the parent model. Here is an example: class CategoryAssociationsObserver < ActiveRecord::Observer observe Supply, Experience def after_save(record) record.category.run_callbacks(:save) if record.category # I don't know if you can trigger just the `after_save` callback here end end See the ActiveRecord::Observer documentation for more information on its use: http://apidock.com/rails/ActiveRecord/Observer.

Categories : Ruby On Rails

Skipping to Next item in Dictionary
Use continue: for key, value in mydict.iteritems(): if key == 'skipthis': continue Also see: Are break and continue bad programming practices?

Categories : Python

Dictionary vs List for looking up an item
Dictionary is faster than List in assimptotic meaning of the word: O(1) < O(n); it means that there's such a size X from which on Dictionary starts being faster than List. E.g. if Dictionary/List contains, say, 10000 or more items, Dictionary is always faster (if there're fewer items to store, say, 5, List can well be faster). There's another issue with Dictionary: it requires GetHashCode() method; if GetHashCode() is bad implemented Dictionary can be deadly slow.

Categories : C#

add an item to array of dictionary
Your objects created from JSON are all immutable. self.seachResult =[NSJSONSerialization JSONObjectWithData:responseData options:nil error:nil]; instead of passing nil for options pass NSJSONReadingMutableContainers: self.seachResult =[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil]; From the NSJSONSerialization docs: NSJSONReadingMutableContainers Specifies that arrays and dictionaries are created as mutable objects.

Categories : Objective C

Dictionary item order
Dictionaries are not ordered at all, so you can't rely on the values there. You could try using OrderedDictionary. If you prefer a generic one, check the following link: No generic implementation of OrderedDictionary?

Categories : C#

An item with the same key has already been added to dictionary
The exception is caused by trying to add an item to the InterfaceSettings Dictionary object which has a key which matches the key of an item that has already been added. I think these are possibilities: The DataTable "tblData" contains rows with duplicate "SettingsName" values. The InterfaceSettings Dictionary object is not empty when you start adding DataRow values and already contains an item with a key matching one of the "SettingName" table row values. The same instance of InterfaceSettings can be seen by two or more threads which access this code. One thread adds an item and subsequently another thread attempts to add the same item. I had a similar issue in my ASP.Net web application where a Hashtable variable belonging to a Module threw an Object not set to an instance of an obj

Categories : Vb.Net

django models that contains list of another model
Use a ForeignKey in the other direction. book should contain a ForeignKey to author, and, by default, author will then contain the member book_set that has a list of all books that are associated with that author. If you intend for a book to be able to have more than one author, a ManyToManyField would be more appropriate. To see all the books by a particular author, you'd want to use author.book_set.all() This page contains an example of a database that uses books, authors, and publishers, where the relationship between authors and books is represented as a ManyToManyField.

Categories : Python

how to create a model that will be associated with two parent models
First of all, you don't need current_user.save as you didn't modify current_user object. :) This should do the trick: @pool.entries.create(new_entry_params.merge(:user_id => current_user.id))

Categories : Ruby On Rails

MVP - Should a Presenter have one overall model or multiple models?
Having different models is not a bad way to do it. This will surely make your design more complex but certainly increase your app's maintainability. If you're building an app that needs to be evolutionary in future upgrades, then seperate your Model into several Models. This will help you in case you want to add a different entity into your app. Maybe your books will be assigned to persons, then you will add a IPersonModel interface and the three other interfaces (INotebookModel, ICategoryModel, IItemModel) will remain intact. However, if your application is simple and you want to favour rapid developement just centralize your model into one big Model. But be careful, if your app gets bigger, this model gets more and more complex since it will handle nearly all the app's responsabili

Categories : C#

How to call an item from a dictionary in python?
It is much easier to have python do the lookup for you. Ignoring empty lines for now: elements = [] for line in open("periodic_table.txt"): elements.append(line[3:]) You can then do a lookup like this: if answer.isdigit(): print elements[int(answer)] else: print elements.index(answer)

Categories : Python

How to Add an item to ArrayList and Dictionary using reflection
To add an Item to a Generic.List<T> you use the Add method Example: MyArray.Add(1); For Generic.Dictonary<T> you also use the Add method, but supply 2 values, Key and Value MyDictionary.Add("MyKey", "MyValue"); So you can just loop though your PropertyInfo[] and add whatever you need to your List<T> or Dictionary<T> foreach(var prop in properties ) { MyArray.Add(a number from somewhere); MyDictionary("some key", "some value"); }

Categories : C#

Naming each item in a list which is a value of a dictionary
If you're just trying to print that: for k, v in dct.iteritems(): print repr(k)+ ":(" + ", ".join("Country{}:{}".format(i,c) for i,c in enumerate(v, start=1)) + ")" Output: 'Europe':(Country1:Germany, Country2:France, Country3:Italy) 'Asia':(Country1:India, Country2:China, Country3:Malaysia) Note: I'm abusing the function of repr() to get the quotes in there. You could just as well do "'" + str(k) + "'". The reason why your code doesn't work is your use of : outside of a dictionary initialization or comprehension. That is, you can do d = {'a':'b'} but you can't do print 'a':'b'. Also, you shouldn't use dict as a variable name, because it is a keyword. My solution will work for tuples which have more (or even less) than 3 elements in them, too.

Categories : Python

Insert item at the beginning of dictionary
Dictionaries are not ordered - they are effectively a Hashtable structure that provides O(1) direct lookups. Therefore you are using the wrong data structure for an ordered collection. You might be better off with a List<KeyValuePair<int, string>> as the List will respect the order that items are added/inserted.

Categories : C#

Python - how to fix the unhashable type: 'dict' and format requires a mapping for operator tripple quotes
This works: arr = { 'pincode':'pincode', 'username':'username', 'password':'password', 'action':'action', 'forward':'forward' } myname="myname" print """my pincode is: %s and my name is: %s !""" % (arr['pincode'], myname) You can also use named arguments with format: print 'my pincode is: {pincode} and my name is: {myname} !'.format( myname=myname, **arr) Note setting the keyword myname to its value prior to setting all the other keywords in the mapping by using **arr. Cheers.

Categories : Python

How do I handle using 1 model to belong_to 2 different models at different times?
I would suggest polymorphic association. class LineItem < ActiveRecord::Base belongs_to :owner, :polymorphic => true end class Order < ActiveRecord::Base has_many :line_items, :as => :owner end class Cart < ActiveRecord::Base has_many :line_items, :as => :owner end you will need to add owner_type and owner_id to line_items table. Refer this

Categories : Ruby On Rails

Have a model with an object I want to connect to two other models (Django)
You can do this: class EventConnect(models.Model) events = models.ForeignKey(MyEvent) eventList = models.ForeignKey(Event, blank="true", null="true", related_name='event_set+') customEventList = models.ForeignKey(customEvent, blank="true", null="true", related_name='customevent_set+') class Meta: unique_together('events', 'Event', 'customEvent') class MyEvent(models.Model): #rest of the fields.. Note that ForeignKey is sufficient in the intermediary table. You cannot assign multiple many to many against the same model field. (like assigning 2 different values to the same database column - which is not possible unless you manage the keys yourself.)

Categories : Django

Django Model Inheritance (is there a way to combine two different models)
You can use a generic relation to do this (more specifically, a 'Generic Foreign Key') from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class Comment(models.Model): comment_author = models.ForeignKey(MyUser, related_name='written_comments') comment_content = models.CharField(max_length=500) comment_date = models.DateTimeField(auto_now_add=True) rating = models.IntegerField(default=0) # These allow you to relate this comment instance to any type of object content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') question = Question(...) question.save() answer = Answer(

Categories : Python

Kohana ORM - has many through models stored in parent model
1) If I understood correctly, you need to get some element from medias $artists = ORM::factory('artist')->find_all()->as_array(); $media = $artists[0]->media->find_all()->as_array(); // media of first artist $name = $media[0]->name; 2) See above $artists is an array of ORM objects

Categories : PHP

What is the norm for positioning models in model space?
There is no standard for this but centering model at origin is a convenient way to do things; it is easier to define bounding volumes this way for primitives you often have simpler formulas defining them. Unless there is some problem with models you have I'd set position of model space origin as world space position this is easiest way to go and works ok in most cases.

Categories : Opengl

Backbone this.model.models undefined error
This issue might because of you are calling the render method in some other place. The collection is only populated after the fetch which is Async . So when the render method is called the model attribute is undefined. So you will see an error. To fix this you have to call render only after the collection is populated and the view initialized.( In the success callback ) bookList.fetch({ success: function () { var bookListView = new BookListView( { model: bookList } ); $('#content').html(bookListView.el); bookListView.render(); // Need to call render here } }); Also why do you want too name in model which inturn is actually a collection. ( { collection: bookList }) makes more sense than ( { model: bookList } )

Categories : Backbone Js

Custom Data Model for multiple Models
Yeah you can, however I think that the currently approach is better. Anyway, you should extend one of your classes to contain other properties (and maybe methods) - in this case, properties of your other classes. To do this, create a partial class some where with the same name as one of those entity classes and the same assembly name. Suppose that the EF generates the following entity class for you: namespace myPrj { public partial class Product { // auto generated class } } Now, you create a partial class like the following: namespace myPrj { public partial class Product { // your partial class. // Add properties of other entity classes here // and you'll have all of them within the Product entity class... } }

Categories : Asp Net Mvc



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.