I am building an Asp Net website in Visual Studio that uses Razor developed HTML pages. I would like to be able to use some C# from the javascript on one of the web pages (this is not creating a plugin that would be displayed in the browser.) I have tried to create a simple Cs class that has a single method that returns a fixed string to test this. The following code is in the ManagedCsClass.cs file is in the App_Code folder in my project.
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ManagedCsClass
{
public ManagedCsClass()
{
//
// TODO: Add constructor logic here
//
}
public string ReturnText()
{
return "Text from ManagedCsClass";
}
}
What I am not clear on is where to create the object that would be used by the HTML page (in the same .cs file as the class, another .cs file, or from a call from the HTML browser page).
And what code do I need to use in the javascript to reference the object/method?
Thanks for any help or guidance you can provide.
Mark
You are trying to use "ActiveX" com objects, this requires the dll containing that class registered on the client and you will have a lot of security/deploy issues ( the client must trust your object and have the framework installed ). It is not the best way to create a web app today.
Related
I would like to be abel to run my angularjs app from the app directory from VS code without using VS2015 and without running iis express. This will make it possible to create new UI very fast specially combined with mocking the service layer.
It's a mvc5 + webapi2 application.
So I need to run /app/index.html from mvc. The index.html is a full html page not an angular template.
Create an action method that returns perticular HTML file. You can return File from controller action. have a look:
public ActionResult Index()
{
var result = new FilePathResult("~/Html/index.htm", "text/html");
return result;
}
Also check this Class: FileResult
Hope this helps!
You can simply call:
return Redirect("~/path/to/.html");
2 ways of doing so:
i. Simple replace the original index.html to your new index.html, all other libraries please place in side the corresponding folder.
ii. in web.config, you may change the maproute properties, you can map your view as default or add new map route.
Thank you.
I am wprking on a project and I have 2 projects in one solution. I added my WCF project and inside it I added an entity framework. Also in Service1.svc I can reach the classes and use them for saving like
public bool saveuser(User user)
{
}
For example User is the name of my database and Its pretty fine working in WCF part but at WPF part Im trying to access this class again to fill this class's object and I using MyClass.ServiceReference1; on the top and Inside one of my method I can not reach this class. What should be the solution why I can not access my class instead I added this WCF service as a service reference and enabled async operations.
Im newbie and thanks
Sincerely
I've split out my domain services into a separate WCF RIA Services Class Library project. However there now seems to be a problem with using the resource strings in the client side library.
e.g.
The client project library has generated code like this:
[DataMember()]
[Display(Description="FullNameDescription", Name="FullNameLabel", Order=-1, ResourceType=typeof(MetadataStrings))]
[StringLength(255, ErrorMessageResourceName="BadFullNameLength", ErrorMessageResourceType=typeof(MetadataStrings))]
public string FullName
{
// ...
}
where MetadataStrings is a resource file in the class library. This class library is then referenced by the silverlight project.
But the meta attributes that use ResourceType cause the designer to throw an exception when opening a view and at runtime cause a MissingManifestResourceException.
If I comment out the attributes and rebuild it all works fine. So something is not right with the resources being in another assembly i'm guessing?
Edit: Nevermind finally got this working, problem was that i renamed my class library projects and the namespace of the resource file was wrong. 3 days wasted.
I have the following Ria Service define:
namespace SilverlightTest.Web
{
[EnableClientAccess()]
public class ContactService : LinqToEntitiesDomainService<AdventureWorksEntities>
{
public IQueryable<Contact> GetContactSearch(string lastName)
{
ContactRepository rep = new ContactRepository();
return rep.SearchByLastName(lastName);
}
}
}
When I compile the solution, my SilverlightTest project does create the SilverlightTest.Web.g.cs file and the appropriate Context objects are created when I look at it. However, when I attempt to import the SilverlightTest.Web namespace to access the Data Context class for the above service, it says it cannot find the Web namespace.
The only difference I can see between what I'm doing and many examples that are out there on the web is that my AdventureWorksEntities data context is located in a separate business object dll. I tried to query the context directly instead of using the Repository Pattern I'm attempting to do and it also isn't work working.
Any ideas? Is it possible to have Ria Services access a separate DLL handling data access or does it HAVE to be in the same project?
I've been able to put the Ria service in a separate project before, although I do remember having issues. Not sure exactly what it was, but I would check two things: your references and your web.config (in the hosting website). When you add a ria service to a web project it does some things behind the scenes that wire everything up correctly.
Could try adding a service to your web project temporarily and see what it adds.
It seems that Resharper does not recognize the .gs files and their name spaces. If you disable R# or just code without intelisense it works.
I'm trying to develop my first Silverlight navigation application. This application has 2 main pages, "Data", and "Analysis". The Data page is where the user can load in a csv file into a custom datatable object :-), whilst the Analysis page is where the user can analyse the datatable.
How do I expose/share the datatable on the Data page so that the Analysis page can access it?
You can also create some class with public static field in it. All these field would be accessible to all pages. So they can be used as globals. Something like that:
public class DataClass
{
public static DataTable DataTable1;
}
I'm pretty uncomfortable with you defining variables in the app class so that they are globally available and I absolutely can't (frankly) see using the disk as an intermediary.
I explore one way to solve this in this tutorial
In SL4 a cleaner way may be to use the Frame to hold a reference to a business object that can be passed among pages. I'll explore that a bit and comment soon.
Thanks
-Jesse Liberty
Make the database an Application Resource or Application Lifetime Object.
Save it into isolated storage and reload it on the Analysis page.
Well in the end I worked out that you could access the Application class at any point through
App app = (App)Application.Current;
and then define your variables in the App class - simple!