I've been trying to bind an android 3rd party library for Xamarin.
I succeeded but there's some Manifest Data I'd like to automatically include
when someone uses my xamarin binding.
For the tag, I figured out I can add them in AssemblyInfo.cs of my binding project and that'll make them appear in the Manifest of the project including my binding.
Now I want to add a bunch of other stuff...
Some , , , , some of them with intent-filters... but I can't figure out how!
From what I read, an element is added to the Manifest when your class has the [Activity] attribute. But the generated .cs binding class doesn't automatically add this [Activity] attribute. Tried to find a way of adding it through MetaData.xml but there doesn't seem to be a way. Tried to add it by using the Additions folder of my binding project but can't seem to make it work. I can't even add a method to an existing bound class actually...
Some help would be welcome :)
Thanks,
Sorry for the delay,
I found the solution to the problem and it's like Jon Douglas said...
The binding project generated classes are all partial so you can add a partial
class with the same namespace and same name to the "Additions" folder and just
add whatever you want to that class. Like an attribute [Activity] for example :)
Thanks!
Related
I have an issue with tag helpers.
All I want to do is create a form that posts data to the controller - basic enough I thought but it doesnt work in my project.
I create a brand new asp.net core web application with default setup and it works there but my project refuses to recognise the tags and act accordingly.
Notably the markup doesnt highlight the same or provide info when hovered over so some ref or something fundamental is missing, can anyone advise.
*Default project working with correct highlights
*My project - not highlighting the code right or working.
Project.json is the exact same so I have no idea whats missing.
FOUND IT!
Microsoft like to change things. So, MVC 6 (asp.net core ...etc) can make use of a _ViewImports.cshtml file in the views folder (feel free to add it yourself if you like me made a project before this existed).
This acts like global import file, and to make the tag helpers available in all your views, you need to add reference here.
Mine now looks like this:
#using Mobile.Models
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
And boom - tags look correct and its work as expected.
You will also face this issue when you create a new Area in the asp.net core MVC project, to resolve it copy ~/Views/_ViewImports.cshtml to ~/AreaName/Views/_ViewImports.cshtml
Make sure that you MUST specify the assembly name and not the namespace.
That was my mistake.
This question has been asked a few times in SO but nothing helped so far in my case.
To an existing MVC project I added a model generated from a database (using database first). Now I would like to add a new API controller. However, neither my new model classes nor my data context class show up in "Add Controller" dialog:
made sure I recompiled my dll
restarted VS (2010)
deleted AssemblyInfo.cs (as suggested in another SO post)
checked with ILSpy to make sure models are in and have an Id
My workaround is to put my models in another dll. However, I think that shouldn't be necessary...
Could it be as simple as a namespace or reference issue.
If they are in different projects then the controller project will eed to reference the respository project.
Can you get to the models by using the full namespace path - you made just need to add a suitable using in the class; typing CTRL+. will give you suggestions.
Hope that helps a little.
I am currently stuck trying to add my own class file into ASP.NET MVC project, so it could
be referenced by my controller. But Visual studio 2010 always complain about "The type or name 'Products' could not be found (are your missing a using directive or assembly reference?)
I am not sure where to put my class file and tried add the class to Models or Controllers directory, and it wouldn't work either. My the class is under the right namespace, and I did reference the Models namespace in my Controller. It could be something obvious, but I couldn't get it working:(
Make sure that the "Build Action" property of the file is set to "Compile" in Visual Studio. Perhaps when you initially added the file, you added it to a location or added it as a file type that did not automatically set the build action properly.
The general rule of thumb is that business objects go it the Models folder you're correct. If it isn't working you don't have the project configured correctly. In the controller where you wanted to reference the Products object, did you add a reference to Models.Products?
Are there any other errors in listed? Sometimes multiple errors in a solution can combine to create something like this.
Ensure the namespace of your class is correct.
Based on a comment to a different answer, it appears you're trying to add a utility or helper class. I suggest you put it in a Helpers folder under the root of the project.
So first add the Helpers folder under the root of the project. You should have the following structure when done (there may be other folders as well):
[project]
- Content
- Helpers
- Controllers
- Views
Now, add a new class to the Helpers folder. Call this class ProductsHelper (in the Add New Item dialog make sure to put ProductsHelper.cs, as it's asking for the file name).
Now have a look in the new ProductsHelper.cs file. Copy the namespace found in said file, to be used in the controller.
Now, add a using directive at the top of your controller that looks like the following:
using [copied namespace];
Sometimes projects are set up to use default namespaces that don't match the project name, in which case the namespace in your newly-added class file might be different than what you thought you should add as the using directive. If you're wondering what the default namespace for your project is, you can see it in the project's properties, on the Application tab, in the "Default namespace" textbox (you can change it here as well).
I had the same problem adding some utility class .cs files to my new MVC project.
I was working mostly on VS 2010 Website projects which compile differently from
Web Application Projects ( WAP ) like the MVC 3 Project.
Just to clarify Jacob's answer, In the VS Solution Explorer: right click on the class .cs file and select the Property Dialog and then set the property: Build Action to Compile.
This will force the code to be compiled when you Build the project.
HTH, LA Guy
This code was generated for me after added entity framework code-first for SQL Server CE using NuGet. They did no changes to any other file. The file SQLCEEntityFramework.cs was created and placed in App_Start folder.
Does this mean it automatically gets executed or something? The same thing happened when I added Ninject for MVC 3. No code was added to the global.ascx file so I have no idea if its plug and play or I have to configure something.
[assembly: WebActivator.PreApplicationStartMethod(typeof(StackTorrents.WebUI.App_Start.SQLCEEntityFramework), "Start")]
According to:
http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx
This new attribute allows you to have
code run way early in the ASP.NET
pipeline as an application starts up.
I mean way early, even before
Application_Start. This happens to
also be before code in your App_code
folder (assuming you have any code in
there) has been compiled. To use this
attribute, create a class library and
add this attribute as an assembly
level attribute. A common place to add
this would be in the AssemblyInfo.cs
class within the Properties folder.
To clarify, it gives you a way of hooking into several application start and application shutdown events WITHOUT having to change any existing code files (previously you had to edit Globals.asax.cs).
This is mostly a big deal when making packages as these events are really useful for bootstrapping Http modules and it is really difficult to write code into existing files.
Trying to create a MVC User Control in the Release Candidate and I can't see to make one with a codebehind file. The same is true for MVC View pages.
Creating Views in the Beta would produce codebehinds...am I missing something?
Code behind kind of defeats the purpose of the MVC Framework. Functionality should be kept separate from the view, the MVC team felt that code behind pages went against this ideology and therefore removed them.
Your can create a custom helper method to create your control. Also I'm not sure if MVC has view components (Monorail/Castle) but that could be an option as well.
From ScottGu's Blog post:
*Views without Code-Behind Files
Based on feedback we’ve changed view-templates to not have a code-behind file by default. This change helps reinforce the purpose of views in a MVC application (which are intended to be purely about rendering and to not contain any non-rendering related code), and for most people eliminates unused files in the project.
The RC build now adds C# and VB syntax support for inheriting view templates from base classes that use generics. For example, below we are using this with the Edit.aspx view template – whose “inherits” attribute derives from the ViewPage type:
One nice benefit of not using a code-behind file is that you'll now get immediate intellisense within view template files when you add them to the project. With previous builds you had to do a build/compile immediately after creating a view in order to get code intellisense within it. The RC makes the workflow of adding and immediately editing a view compile-free and much more seamless.
Important: If you are upgrading a ASP.NET MVC project that was created with an earlier build make sure to follow the steps in the release notes – the web.config file under the \Views directory needs to be updated with some settings in order for the above generics based syntax to work.*
I answered this question here:
How to add a Code-behind page to a Partial View
Seems this wasn't particularly tricky, and is quite do-able
This answer worked for a Partial 'ViewUserControl' but the same should apply
Ok.
First: Add a Class file with the convention of .cs (i.e. view.ascx.cs)
Second: Add "using System.Web.Mvc;" to the class
Third: Change the Class to Inherit from "ViewUserControl<>"
Fourth: Add the following to the View's header:
CodeBehind="View.ascx.cs" Inherits="Project.Views.Shared.View"
Fifthly: Copy the files out of the solution and drag back in to reassociate the two together
Note: For this to work with a Normal MVC View you just need to inherit the class from "ViewPage"
The whole idea for ASP.Net-mvc was to get rid of the codebehind files...thats why asp web controls didnt matter that most didn't work.But with the changes of getting rid of the code behind comes with a different programming style..The idea is codebehind files are EVIL:
http://stevesmithblog.com/blog/codebehind-files-in-asp-net-mvc-are-evil/
the whole idea is to make sure people remember they are using asp.Net-mvc and not asp.et web pages. take alook at this link ,it explains it a little better:
http://blog.lozanotek.com/archive/2008/10/20/Visual_Studio_Templates_for_MVC_Views_without_Codebehind_Files.aspx
I think this tutorial is what you are asking.. but not really sure what you want..