I am using mvc 5 and creating ViewComponent. Facing namespace missing reference error.
The type or namespace name 'ViewComponent' could not be found (are you
missing a using directive or an assembly reference?)
here is code sample
public class SumViewComponent : ViewComponent
{
public IViewComponentResult Invoke(int a, int b)
{
return this.Content($"<span class=\"result\">{a + b}</span>");
}
}
How can i resolve namespace issue, is it supported in mvc 5 application.
MVC 5 does not have ViewComponents, they were introduced with MVC 6. See this article
Related
I'm porting some code over from a Kentico 8.2 build to a Kentico 11 website. One of the snippets that I am migrating makes use of a CMS.Ecommerce.IAddressExtensions extension method public static string GetStateCode(this IAddress address).
When I moved this over to my Kentico 11 build, Visual Studio finds that this extension method no longer exists: IAddress does not contain a definition for GetStateCode and no extension method could be found.. I poked around the Object Viewer for the CMS.Ecommerce DLL, and sure enough, no IAddressExtensions class is present.
Is there a workaround to look up the state code for a given address in Kentico 11?
As you found out, Kentico has removed the IAddressExtensions class when upgrading from version 10 to 11. Here is the page for the API change.
Based on my understanding, you will instead need to use the StateInfoProvider as below.
IAddress someAddress = /* snip */;
var stateInfo = StateInfoProvider.GetStateInfo(someAddress.AddressStateID);
var stateCode = stateInfo.StateCode;
You can then take this same logic and move it into your own extension class.
public static class IAddressExtensions
{
public static string GetStateCode(this IAddress address)
{
var stateInfo = StateInfoProvider.GetStateInfo(address.AddressStateID);
return stateInfo.StateCode;
}
}
Was EphemeralKeyRing omitted from GitHub for Security Reasons?
This one is a brain teaser. I've spent quite a bit of time lately reading and and absorbing the hierarchy of classes that relate to asp.net core session storage and asp.net core data protection. In those journeys, I have come across a reference to a EphemeralKeyRing class. However, the code for this class does not seem to be in the Asp.Net Core source code repository on GitHub. Equally odd, when doing a google search on this class name, I can find no references anywhere on the internet that are about this asp.net core class other than the one GitHub source code file that uses it.
Here is the class that news up a EphemeralKeyRing object: https://github.com/aspnet/DataProtection/blob/rel/1.1.0/src/Microsoft.AspNetCore.DataProtection/EphemeralDataProtectionProvider.cs
Here's the results of a GitHub search for the EphemeralKeyRing class in the Asp.Net Core repository:
:
And here is the an amazingly sparse set of google results when searching for EphemeralKeyRing. Note the first entry is the code file on GitHub that I mentioned above which uses the object and the other results are unrelated to this asp.net core class.
So my question is this: Was the source code for the EphemeralKeyRing class omitted from GitHub purposely for security reasons? Or is it there and I'm just searching wrong?
Here is the link:
https://github.com/aspnet/DataProtection/blob/master/src/Microsoft.AspNetCore.DataProtection/EphemeralDataProtectionProvider.cs
which I see you found and clicked on it already. If you go to the bottom of the page youll see the class you are looking for, I'll paste the code just in case:
private sealed class EphemeralKeyRing<T> : IKeyRing, IKeyRingProvider
where T : IInternalAuthenticatedEncryptionSettings, new()
{
// Currently hardcoded to a 512-bit KDK.
private const int NUM_BYTES_IN_KDK = 512 / 8;
public IAuthenticatedEncryptor DefaultAuthenticatedEncryptor { get; } = new T().ToConfiguration(services: null).CreateNewDescriptor().CreateEncryptorInstance();
public Guid DefaultKeyId { get; } = default(Guid);
public IAuthenticatedEncryptor GetAuthenticatedEncryptorByKeyId(Guid keyId, out bool isRevoked)
{
isRevoked = false;
return (keyId == default(Guid)) ? DefaultAuthenticatedEncryptor : null;
}
public IKeyRing GetCurrentKeyRing()
{
return this;
}
}
I'm trying to create a custom html helper class.
I have the below as a very simple start, complies fine:
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Mobile.HtmlHelpers
{
public static class RequestBox
{
public static HtmlString CascadeBoxFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, object htmlAttributes = null)
{
HtmlString html = (HtmlString)HtmlHelperInputExtensions.TextBoxFor(helper, expression);
return html;
}
// IHtmlContent html = HtmlHelperInputExtensions.TextBoxFor(htmlHelper, expression);
}
}
I am trying to call it and the system doesn't like it..
I can see it if I use:
#foreach (var item in Model.RequestModel.Requests)
{
#RequestBox.CascadeBoxFor(x=>item.EmployeeDescription)
}
But I get:
Severity Code Description Project File Line Suppression State
Error CS7036 There is no argument given that corresponds to the required formal parameter 'expression' of 'RequestBox.CascadeBoxFor<TModel, TValue>(HtmlHelper, Expression<Func<TModel, TValue>>, object)' Mobile..NET Framework 4.6.1
If I try suggestions of it being an extension and I should be able to use #Html.CascadeBoxFor(x => item.EmployeeDescription), I get:
Severity Code Description Project File Line Suppression State
Error CS1061 'IHtmlHelper<RequestPageModel>' does not contain a definition for 'CascadeBoxFor' and no extension method 'CascadeBoxFor' accepting a first argument of type 'IHtmlHelper<RequestPageModel>' could be found (are you missing a using directive or an assembly reference?) Mobile..NET Framework 4.6.1
Can anyone tell me what is missing here?
I have visual studio 2013 installed with web essentials 2013. I right-click a .cs file and select "Web Essentials -> Create Typescript intellisense file", such that I get a typescript d.ts file that I can reference in the typescript code. I ran into a few issues with this. Let's say my class is as follows:
namespace SomeNamespace
{
[TypescriptModule("test")]
[DataContract(Name = "MyDTO")]
public partial class MyPM
{
[DataMember(Name = "id")]
public long Id { get; set; }
[Required]
[DataMember(Name = "name")]
public CustomPM Data{ get; set; }
}
}
The d.ts file I get is:
declare module test {
interface MyPM{
id: number;
data: test.CustomPM;
}
}
The first problem is that the line:
[DataContract(Name = "MyDTO")]
is being ignored during generation. It is not generating a class called MyDTO, but a class called MyPM, even though MyDTO is the string specified for use during serialization and that's what goes over the wire to the client. I did some investigation and the code here:
https://github.com/madskristensen/WebEssentials2013/blob/master/EditorExtensions/Commands/Code/IntellisenseParser.cs#L207
indicates that it uses CodeClass.Name property to determine the class name. Is there a way to use attributes on the class (something besides DataContract Name) to make the CodeClass.Name property contain another string besides the actual class name?
The second problem is this line:
data: test.CustomPM;
In visual studio 2013 with typescript installed, test.CustomPM gives me an error because it is unable to find the type CustomPM in the test module, even though the class has been generated into the same "test" module and is available for use. The part that is missing is this line at the top of the d.ts file:
/// <reference path="./CustomPM.cs.d.ts"/>
However, I have been unable to find a way to have the generator generate this as well.
I would really appreciate is anyone can shed some light on ways to work around these issues. Thanks!
It is an old question, and I will not answer directly because I didn't know this fonctionnality of WebEssentials.
But i will give you an alternative that works really well :
TypeLite - http://type.litesolutions.net/
You just have to put the attribut [TsClass] on the classes that you want.
If you want your TS interface to start with I and all properties camelCase, edit TypeLite.Net4.tt :
var ts = TypeScript.Definitions()
.WithReference("Enums.ts")
.ForLoadedAssemblies()
.WithFormatter((type, f) => "I" + ((TypeLite.TsModels.TsClass)type).Name)
.WithMemberFormatter((TypeLite.TsModels.TsProperty identifier) => Char.ToLower(identifier.Name[0]) + identifier.Name.Substring(1));
You can reference your generated types in your base tsconfig.json, then you don't need the custom reference in every typescript file:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"jsx": "preserve"
},
"files": [
"../typings/index.d.ts",
"./TestForm.tsx",
"./declaration.d.ts",
"../models/models.cs.d.ts"
]
}
I'm trying to create module for magento. It use my own class
class Myfirm_Extname_Model_Mysql4_Product_Option extends Mage_Catalog_Model_Resource_Product_Option
In magento 1.7 all works fine, in 1.5 - error: Error class Mage_Catalog_Model_Resource_Product_Option not found.
How can I make class that will be inherited from Mage_Catalog_Model_Resource_Product_Option or Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option depending on the version of magento?
I solved this prodblem.
protected function _getResource() {
if (version_compare(Mage::getVersion(), '1.6.0', '<')) {
$this->_resourceName = $this->_resourceName.'_oldversion';
}
if (empty($this->_resourceName)) {
Mage::throwException(Mage::helper('core')->__('Resource is not set.'));
}
return Mage::getResourceSingleton($this->_resourceName);
}
And then create 2 resource model class for old version of magento and new