w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to handle a strongly typed modal in a strongly typed view with different types
There is an overload in @Html.Partial that takes an object, used for the partial page's Model. If you include the Partial in your layout, in every page, you need a logic to keep that data. For example, if you take LoginModel and RegisterModel, you could do this: @Html.Partial("_LoginPartial", ViewBag.LoginModel ?? new LoginModel()) @Html.Partial("_RegisterPartial", ViewBag.RegisterModel ?? new RegisterModel()) And leave to the executing controller the role to put a LoginModel (or RegisterModel). If there isn't any in the ViewBag, it will fallback to creating an empty one. Edit: Based on the additional information, I'd do this for the LoginPartial (RegisterPartial would be the same logic): public class AccountController : Controller { public ActionResult LoginPartial() {

Categories : C#

Strongly Typed String
I would recommend another design. Define a simple interface that describe a parsing rule (string syntax): internal interface IParseRule { bool Parse(string input, out string errorMessage); } Define the parsing rule for a user name (and the other rules that you have): internal class UserName : IParseRule { public bool Parse(string input, out string errorMessage) { // TODO: Do your checks here if (string.IsNullOrWhiteSpace(input)) { errorMessage = "User name cannot be empty or consist of white space only."; return false; } else { errorMessage = null; return true; } } } Then add a couple of extension methods to that utilize the interface: internal static class ParseR

Categories : C#

strongly typed enums in g++-4.4
It's a known bug. As @Casey found out, originally g++-4.4 did not support any relational operations on strongly-typed enums. For equality, this was fixed in version 4.4.1, but the fix for all other relations such as < and > only made it into 4.5.1 and above. This is the original bug thread on the gcc bugzilla: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38064

Categories : C++

Typed vs Strongly Typed in C#
Your nomenclature is incorrect. it is not strongly typed vs just typed It's strong vs. weak typing Once you talk about it in those terms, then there is a big distinction to be made. You can read about it all over teh Googles. http://en.wikipedia.org/wiki/Strong_and_weak_typing#Definitions_of_.22strong.22_or_.22weak.22 Edit: There is no such thing as just a Typed language. You have Dynamic vs Static and Weak vs Strong typing which are addressing two different types of issues. Another reference article What is the difference between a strongly typed language and a statically typed language?

Categories : C#

Is Arraylist is typesafe or strongly typed?
Type-safe and strongly-typed are loaded phrases, such that it's hard to get programmers everywhere to pin down a precise definition. But there is at least enough consensus to state that ArrayLists are neither in every way that matters. Do not use ArrayLists! Instead, use the generic List<T> collection.

Categories : Dotnet

Strongly typed access to csv in scala?
If you know the the # and types of fields, maybe like this?: case class Friend(id: Int, name: String) // 1, Fred val friends = scala.io.Source.fromFile("friends.csv").getLines.map { line => val fields = line.split(',') Friend(fields(0).toInt, fields(1)) }

Categories : Scala

Getting sub property names strongly typed
This is a modified version of something I might have found here on StackOVerflow: public static class GetPropertyNameExtension { public static string GetPropertyName<TArg, TProperty>(this Expression<Func<TArg, TProperty>> propertyExpression) { return propertyExpression.Body.GetMemberExpression().GetPropertyName(); } public static string GetPropertyName<TProperty>(this Expression<Func<TProperty>> propertyExpression) { return propertyExpression.Body.GetMemberExpression().GetPropertyName(); } public static string GetPropertyName(this MemberExpression memberExpression) { if (memberExpression == null) { return null; } if (memberExpression.Member.MemberType != Membe

Categories : C#

How to group a strongly typed model
This: @Model.IPACS_Department.IPACS_Functions.SelectMany(m => m.IPACS_Processes) .SelectMany(m => m.IPACS_Procedures).SelectMany(m => m.IPACS_KPIS) .SelectMany(m => m.IPACS_kpiHistory) gives a list of denormalised kpiHistories, yes? Does it not give you the answer you want if you do thatList.GroupBy(x => x.kpiID)

Categories : C#

Strongly-typed view not initializing?
I had a similar issue. In order to get MVC to work with collections well, I found it's best to use a for loop instead of a foreach loop in the view. When you are using the Html helper, access the values using an indexer in your expression, this will cause Razor to use that indexer in the name of the form control. On your controller, accept a collection (array for sure, you may be able to get away with IEnumerable<>) and it should work. Since you are using a class as your model and not the collection directly, you may need to either use the BindAttribute on your action parameter to let MVC know that the request data will have a prefix, or use another class that has a property with the same name as the property in your EstimationManager class as the action parameter. Just view source

Categories : C#

Data not showing in the strongly typed view
In your controller all you do is instantiate a new ClientModel object and add it to the list. Is that really what is in your index method? If so, the properties would be null and the issue is with your controller not your view. If not, could you post what your index method actually does? Also, in your ClientModel the property is CanaClie0012 so how does CanaClie0012.toList() come into play? Update I'm not sure how CanaClie0012 and Clientes0013 are related though I am assuming they are given that you are grouping them together within the ClientModel. For the sake of an example lets modify them by adding an id field in CanaClie0012 and a corresponding field in Clientes0013 so that we can join the two classes. Again, I'm only doing this to show what the controller might look like. So now we

Categories : Asp Net Mvc

LINQ to XML - select to a strongly typed object (VB)
Just skip class name: Dim x = From a In response...<artist> _ Select New With { .MBID = a.@id, .Name = a.<name>.Value, .Gender = a.<gender>.Value } But it will give you IEnumerable(Of T), where T is an anonymous type. You should not return objects like that from your methods: For example, an anonymous type cannot be used to define a method signature, to declare another variable or field, or in any type declaration. As a result, anonymous types are not appropriate when you have to share information across methods. Edit To get only one element from collection use First/FirstOrDefault methods: Dim x = (From a In response...<artist> _ Select New With { .MBID = a.@id, .Name = a.<name>.Value }).FirstOrDefault();

Categories : Vb.Net

Strongly typed Linq filtering method
Have you tried simple || conditions? return _db.Entities .Where(x => id == null || x.Id == id.Value) .Where(x => startDate == null || x.StartDate >= startDate.Value) .Where(x => endDate == null || x.EndDate <= endDate.Value) .Where(x => statusId == null || x => x.EntityStatus.StatusID == statusId); ? I would expect that after query optimization, the no-op filters would be equivalent to not adding the filters at all.

Categories : C#

Strongly typed global data in ASP.Net Web Pages
That's a pretty good approach. I'd simplify it a bit: public sealed class GlobalData { public static GlobalData Current { get { // soft cast using "as" which will return null if the type is not correct var globalData = WebPageContext.Current.PageData["GlobalData"] as GlobalData; if (globalData == null) { // Need to instantiate globalData = new GlobalData(); WebPageContext.Current.PageData["GlobalData"] = globalData; } return globalData; } } public string SomeData { get; set; } }

Categories : C#

VB strongly typed model access in MVC4
Views use a class called a WebViewPage. That's what a view is. The reason you have access to an object called Model is because of this (notice that it's a property of the class). You can access the model at any time in a Razor view with @Model. @Html is the way we access Html helpers (HtmlHelper) from our Razor view; useful for generating some HTML for us. DisplayNameFor() is one of many extension methods. That long, scary parameter that it wants is actually relatively simple. Basically it wants you to give it an anonymous function. This technique is called a Lambda Expression. In C# (for comparison) it might look like this: SomeMethod(x => x.SomeProperty); It's basically a short-hand way of creating a function on the spot (typically on one line) and doing something with the proper

Categories : Asp Net Mvc

The simplest way to have a strongly typed array with 2 datatypes?
The simplest way to do this is to use the Tuple class. You can use Tuple with generic parameters to combine classes to form tuples. For example, Tuple<string, int> or Tuple<string, int, int?, char>. Here is documentation of the 2-parameter version. In the case you described, you probably want an instance of type Tuple<string, int>[]. You can access the elements of the Tuple using the ItemX methods: myTuple.Item1, myTuple.Item2, etc. In order to actually create the tuples, I recommend using the Tuple.Create methods. For example: Tuple.Create("hello", 1) will return a Tuple<string, int> with the items set correctly. These Create methods allow you to omit the generic parameters. As a side note, you mentioned that you don't need sorting. You can get arbitrary

Categories : C#

Strongly Typed Model naming override
Have you tried this one: @Html.LabelFor(m => m.IPACS_kpiHistory.startAmount, "Starting Amount") or by decorating your view model property with the [Display] attribute: [Display(Name = "Starting Amount")] public double startAmount { get; set; }

Categories : Asp Net Mvc

What does "Strongly Typed" Actually Mean in Actionscript 3 for Both Flash and Flex?
Also I know in Flex you pretty much always declare the type as the name of the class. It it true then that Flex uses strongly typed variables and Flash does not? This was getting too big for a comment. You seem to be confused as to what Flash and Flex are. Flash primarily refers to either a browser based runtime named The Flash Player or a graphical IDE named Flash Professional. Flex is formally a software development kit (SDK). However, the term Flex can be used to refer to The Flex Framework, which is an ActionScript 3 UI framework. It can also be used to refer to the Flex Compiler which is used to turn MXML and ActionScript into SWFs. The current language of the Flash player is ActionScript 3. If I'm understanding your question, then I would expect both Flash Profe

Categories : Actionscript

Using generics for strongly typed event handlers?
You can just pass the generic type to the argument.. like this: class Receiver { public RegisterEvent<T>(T param); } The T in the argument list must match the type provided into the call. EDIT: Having re-read the question.. perhaps this is actually what you meant: public delegate void CustomEventHandler<T>(T param); public void RegisterEvent<T>(CustomEventHandler<T> eh) { } ..same philosophy though.

Categories : C#

Strongly typed dataset Playing up big time
It might be that it's returning 1 for the inserted record due to not having SET NOCOUNT ON; in the SP. Try adding this, it should solve the issue. Not having this will give you the amount of affected records, 1 in your case. USE [DataBaseName] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE procedure [dbo].[InsertRecord] ( @a int, @b int ) AS SET NOCOUNT ON; INSERT Into tableName Values ( @a, @b ) return SCOPE_IDENTITY()

Categories : C#

What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?
@(Html.ActionLink<CustomersController>(x => x.Index(), "Customers")) The Basics – (Strongly-Typed) Linking to MVC Actions This question covers it loosely.

Categories : Dotnet

Strongly typed Query not translated as expected
Yes, something similar is possible, it doesn't create the same query, but for the query given, it doesn't make a difference: var query = from c in collection.AsQueryable<Trip>() where c.Id == trip.Id where c.Expenses.Any(p => p.Id == myId) select c; or var query = collection.FindAs<Trip>( Query.And( Query<Trip>.EQ(p => p.Id, trip.Id), Query<Trip>.ElemMatch(p => p.Expenses, q => q.EQ(x => x.Id, myId)))); However, note that both will create an $elemMatch query like this: { "_id" : ObjectId("522512c5298f241198548b9d"), "Expenses" : { "$elemMatch" : { "_id" : ObjectId("522512c5298f241198548b9b") } } elemMatch will check if one single element in the array matc

Categories : C#

Difference between strongly and weakly typed languages?
Check Eric Lippert's blog out. There's an entry about just what you're looking for here. From the looks of his blog, those terms are subjective, so "speak more precisely about type system features."

Categories : Misc

How to create strongly typed list class in vb.net
In VB you can make a list of a custom object. dim oSubscriberList as new List(of Subscriber) Then you can instantiate new subscribers and add them to the list oSubscriberList.add('add object here') This is probably the most simple, quick and dirty way to handle it. You can also create a separate class to create a collection of your object. "Best" practices, if you want to follow SOLID programming principles and use test driven development, would point you towards making a separate collection class to deal with it, but it isnt necessary. EDIT: as per comment below You dont need to create a subscriberlist class. Just create a regular list of Subscribers and add them to the list as so. Do this where you are wanting to create this list (form load, some event, etc.) Dim oSubscriberLi

Categories : Vb.Net

How to get the original values of an entire strongly typed DataRow?
I am afraid you will likely strike out across the board here. The difference between the Original and Modified RowVersion only exists until AcceptChanges() is called...a finite period. And the Columns collection at its heart is an ArrayList, with these accessors: public DataColumn this[int index] { get; } public DataColumn this[string name] { get; } I don't see how you'd find a DataColumn any other way.

Categories : C#

Generic method to compare 2 strongly typed list
To get the difference between two sets (with order independency and multiplicity independency), you can use: HashSet<T>.SymmetricExceptWith(IEnumerable<T>). public static IEnumerable<T> GetSymmetricDifference<T>(IEnumerable<T> list1, IEnumerable<T> list2, IEqualityComparer<T> comparer = null) { HashSet<T> result = new HashSet<T>(list1, comparer); result.SymmetricExceptWith(list2); return result; } In your case, to use it: var difference = GetSymmetricDifference(list1, list2, new MyComparer()); With a custom comparer: public class MyComparer : IEqualityComparer<MyType> { public bool Equals(MyType x, MyType y) { return x.Name.Equals(y.Name); } public int GetHashCode(MyType obj) {

Categories : C#

Passing strongly-typed data from a View to a Controller
The fact that your view is strongly typed to @model MyNamespace.Customer doesn't mean that this model will somehow be automagically posted to your action when the form is submitted. Basically you need to have input fields for each property you want to retrieve inside your form if you want this property to be passed to your POST action. Also make sure that this Customer object is a POCO with a default (parameterless) constructor where each property you would like to retrieve has public getters and setters. Otherwise the default model binder will never be able to deserialize the request to this model. The ideal solution to this problem is to use a view model which is a class that you specifically design to meet the requirements of your view and stop passing your domain models to it. This vi

Categories : C#

Get the PropertyValues inside the Create (HttpPost) - Not strongly typed
Try using a FormCollection public ActionResult Create(FormCollection collection) { //Can access any propertyvalues, but its not dynamic! } You can then access the values with something like this string s = string.Empty; foreach (var key in collection.AllKeys) { s += key + " : " + collection.Get(key) + ", "; }

Categories : C#

Suggestions for MVC strongly typed view with lots of fields
If all these fields are a parts of something big, I would create one table in DB. Later it will be easely to work with and faster than searching data in different tables. As to 371 fields in your form, I think they can logicaly be devided by groups. In that case I would use jQuery to devide process by steps: Step1: show first ten fields; Step2:Hide first fileds and show next ten fields an so on. Technically it can be done by just playing with hide() and show() jQuery methods.

Categories : Asp Net Mvc

C# passing a list of strongly typed property names
Use the params keyword to define a method that takes a variable number of arguments: public static void PrintPropertyNames<T>(params Expression<Func<T, object>>[] properties) { foreach (var p in properties) { var expression = (MemberExpression)((UnaryExpression)p.Body).Operand; string memberName = expression.Member.Name; Console.WriteLine(memberName); } } For instance, you could call the PrintPropertyNames method passing two expressions: PrintPropertyNames<FileInfo>(f => f.Attributes, f => f.CreationTime); This example displays the following output to the console: Attributes CreationTime

Categories : C#

How to include more than 1 model object in a strongly typed view?
It`s not possible. You should create another Model to wrap this two models. Example: //Model public class FooModel1 { public string Property {get;set;} } public class FooModel2 { public string Property {get;set;} } public class FooModel { public FooModel1 One {get;set;} public FooModel2 Two {get;set;} } //Controller: public ActionResult Index() { var model = new FooModel() { One = new FooModel1 (), Two = new FooModel2 ()}; return View(model); } //View @model FooModel @Html.TextBoxFor(m=>m.One.Property) @Html.TextBoxFor(m=>m.Two.Property)

Categories : Asp Net Mvc

What is the best way to create strongly typed LINQ queries from some given strings, via reflection
My answer depends on whether you are happy to alter your access model slightly. I've got a similar situation in an application that I have written and personally I don't like the idea of having to rely on my calling code to correctly filter out the records based on the users authentication. My approach was to use an OData service pattern to call into my Entity Framework, each of the repositories are exposed via OData independently. An OData (WCFDataService) has QueryInterceptors which perform on the fly filtering of your data when a query is made. Thus if you asked the OData repository for context.Orders(o => o.Id) you'd only see the orders that that user was permitted to see with no additional clauses. A good link to the basics is found here but it requires some work to manage the ca

Categories : C#

Strongly typed list return from View to fill Model?
I believe to hydrate a list of entities during model binding the names of the properties of the entity need to be prefixed with an index like so: @Html.CheckBoxFor(model => model.Employees[0].IsChecked) @Html.HiddenFor(model => model.Employees[0].LastName) @Html.HiddenFor(model => model.Employees[0].FirstName) @Html.HiddenFor(model => model.Employees[0].EmployeeId) @Html.HiddenFor(model => model.Employees[0].Building) This is how MVC knows to create a new EmployeeForList entity and add it to the Employees list. NOTE: model here would be IndexModel.

Categories : C#

Is there a C# pattern for strongly typed class members with external set/get methods?
This pattern allows loosely coupled resource keys. A hashmap that excepts any key type, for the purpose of extensibility. You often see this with system messages in IoC containers. In my experience, this pattern grants great flexibility with the cost of required documentation. Consider solving the problem with convention rather than implementation. I try to stick to enumerated values where possible. They are immutable primitives with strong names. They can be groupedinto their parent type. They can be iterated quite simply if required. They respond to refactoring.

Categories : C#

Strongly Typed Model using HttpPostedFileBase fails to Scaffold Views
I don't think you will be able to HttpPostedFileBase as a property of your model, well at least not have it mapped via EntityFramework and automatically scaffolded. If you think about it - what database fields do you think this property type would map to? If you want to actually store the binary data in your database, use this public byte[] File { get; set; } as your property.

Categories : C#

How would I add array values to Model data dynamically for a Strongly-Typed View?
int[] projectInt = new int[3] { 1, 2, 3 }; List<ProjectTracking> projects = new List<ProjectTracking>(); foreach (var i in projectInt) { var project = new ProjectTracking{ ProjectID = projectInt[i], ... } projects.Add(project); }

Categories : Asp Net Mvc

.NET Custom Strongly Typed HTML Helper with deep property navigation
ModelMetadata.FromLambdaExpression(propertyExpression, html.ViewData); This is what you are looking for. Unfortunately, this means that html must be an instance of HtmlHelper from a view whose model is the type you're trying to get the metadata for. I think that's because it wants to take the property values from the Model/ViewData and pass it by the ModelMetadataProvider to allow it to to populate metadata specific to the model instance in question. If you don't care about instance-specific metadata (eg: only want data annotation attributes) and so on, then just pass it a new ViewDataDictionary (where TModel is the type whose metadata you want to get). For bonus feel-good points, the FromLambdaExpression method caches expressions and their resolved property paths inside it to give be

Categories : Dotnet

Strongly-typed view binding a collection of objects without getting screwed by ModelState
So this works, but it's awful. I'm posting it here in hopes that somebody has a better solution. If I do it this way, I essentially have to maintain two sets of form code. I've added a "primary key" field to DataObject, and I check if that's the item being modified by peeking into Request.QueryString. If it is, I use HTML Helpers. If not, I use plain old input tags. But I can't possibly believe this is the best way to handle it. ModelsDataObject.cs: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ModelStateTest.Models { public class DataObject { public int Key { get; set; } public string Field1 { get; set; } public string Field2 { get; set; } public string Field3 { get; set; } } } ControllersHomeCo

Categories : Asp Net Mvc

ASP.NET MVC 3 Strongly-typed Views: Why do compiler errors disappear/are ignored when a view is not open in VS editor?
You can compile cshtml and aspx files at build time instead of runtime. To do this unload project, open it for edit, find <MvcBuildViews> tag and change value to true. If you have edmx files in your project clean solution before first edit.

Categories : Asp Net

Mixed MVC4 into existing ASP.NET Webforms project and now strongly typed views don't recognize the type of the model
You may be missing some key MVC Assemblies in the web.config: <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </d

Categories : C#

How to release correctly memory in iOS: Memory is never released; potential leak of memory pointed to by
You need to free the bytes, because NSData does not take ownership of it: it cannot know if the array is a temporary or a dynamic, so it makes a copy of it. To fix this problem, replace return [NSData dataWithBytes:bytes length:c]; with NSData *res = [NSData dataWithBytes:bytes length:c]; free(bytes); return res;

Categories : IOS



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