Telerik not showing in intellisense of VS 2008 - asp.net-mvc

I was coding an aspx page to use the telerik grid. But telerik is not showing in intellisense of VS 2008.
Following are the things done so far:
1. Added the telerik dll in the reference folder.
Code part
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage"%>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%# Import Namespace="Telerik.Web.Mvc" %>
Index
<% foreach(var v in (List<String>)ViewData["names"])
{
Response.Write(v);
%>
<br />
<%
}
%>
<% Html. %>
Thanks

The Visual Studio Intellisense in views is far from perfect. Personally what I do is to add the assembly (<assemblies> tag) and the namespace (<namespaces> tag) in web.config, so that it is available in all views. This way I no longer need to add any Import section in each view. After doing this you probably might need to reopen the view for the changes to take effect. Even restart Visual Studio. If it works at runtime and you don't get Intellisense at compile-time, well, I wish they improve it in future versions.

Related

Custom form in Umbraco limitations?

I am busy learning about Umbraco but I don't see anything on the internet that tells me if Umbraco will allow me to create a custom ASP.NET form using C# code connecting to a SQL Server Database.
Would I have any issues with Umbraco if I need to create such a custom form in ASP.NET and bring it into Umbraco?
There are two ways (that I know of, at least) where you can implement custom .Net forms in Umbraco (Version 4.7.x and below).
Template-Based
You can build the form directly in the template markup using standard ASP.Net controls and using a <script runat="server" language="c#"> tag. This is standing inline page coding as you would in Visual Studio, so you give up the luxuries of pre-compilation etc.
<%# Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<asp:Label ID="myLabel" runat="server" />
</asp:Content>
<script runat="server" language="c#">
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.myLabel.Text = "Hello World";
}
}
</script>
Macro-Based
Build your forms in User Controls in Visual Studio and compile it.
Copy the .ascx to the /usercontrols/ folder.
Copy the .dll to the /bin/ folder.
Navigate to Developer > Macros in Umbraco and create a new Macro
Select your user control from the drop down next to .Net User Control on the Macro Properties tab.
Import you macro into your template. Done!
(Optional) If you user control requires properties to be set, don't forget to add them to properties tab in your macro and map them.
Your template code will look something like the following:
<%# Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<umbraco:Macro Alias="MyForm" MyProperty="Hi!" runat="server" />
</asp:Content>
Another fast and cheap option is using the Contour Forms package. It costs about 99 euros and provides a WYSIWYG interface to creating forms. It has workflow and the ability to store the values in custom tables.
We really like it and it works for probably 75% - 80% of cases where you need a form.
http://umbraco.com/products/more-add-ons/contour.aspx
You can definitely do this in version 4.7 (and earlier versions), by creating a asp.net custom control, and then adding it into the system - its all pretty easy to do.
In V5 you can't create custom controls since it is now MVC based, and as I am just getting upto speed on v5, can't comment on how hard/different it is yet.
Which version are you using?

Problem with ASP.NET MVC Edtior Templates

I am trying to create an editor template for column in a Telerik MVC Grid. After clicking edit this simple string column should show the same string value and next to it I would like to show a button or image with an onclick event.
I CAN'T DO THIS!
I have found some really simple examples. Let's forget about the button or image for now and just display the same damn string, based on instructions found in this article:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.Encode(ViewData.TemplateInfo.FormattedModelValue) %>
and:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= ViewData.TemplateInfo.FormattedModelValue %>
or:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Model %>
None of these work. In fact, when I step into this server side, ViewData.TemplateInfo.FormattedModelValue and Model don't have a value. What's going on? What is it in the grid that is preventing this? More complex Editor Templates like comboboxes persist the data back to the editor template.
How can I simply display the same text in an editor template with some further options like buttons that I will later change the data?
Steve
Steve, can you provide a sample of your controller code? It sounds as though it's not setting the model data correctly.

Visual Studio MVC Oddity?

I've been stuck on the same DropDownList problem for days now while working on a MVC project in VS2010. The problem has become even more frustrating right now because when I copy all relevant code into a completely new, blank project, the second instance actually runs perfectly and produces exactly the result I expect...
Controller:
<HandleError()> _
Public Class HomeController
Inherits System.Web.Mvc.Controller
Function Index() As ActionResult
ViewData("Message") = "Welcome to ASP.NET MVC!"
Return View()
End Function
Function About() As ActionResult
Dim configList As List(Of String) = New List(Of String)
configList.Add("10GBaseLX4")
configList.Add("10GFC")
configList.Add("10GigE")
configList.Add("100BaseFX")
configList.Add("Test")
ViewData("cprotocols") = New SelectList(configList)
Return View()
End Function
End Class
View:
<%# Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="aboutTitle" ContentPlaceHolderID="TitleContent" runat="server">
About Us
</asp:Content>
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>About</h2>
<p>
<% Using Html.BeginForm()%>
<%= Html.DropDownList("cprotocols") %>
<% End Using %>
</p>
</asp:Content>
The page doesn't do anything right now other than simply display a dropdownlist with the options shown hard-coded in the controller, but I'm not even going to bother with writing logic when my current site refuses to even show the list to the user.
The error message is There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'cprotocols'. but once again, there are no runtime errors when i copy this bit of code over to a blanked solution.
Any ideas how to solve this or even any clues on what is causing such an inconsistency? I don't want to copy over all the other files from my current project into the new one just to have the problem manifest itself again somewhere down the line (which is bound to happen when the code is only half broken...)
I would try changing the ViewData key name and see if that helps anywhere. If not, if you can you could create a new project and copy all your existing model/controller/view classes over the other project, this seems like something in your project configuration that could have gone off.
Hope this helps a little :)
Turns out it was a problem with the module; the code itself is fine. I had to delete Temporary ASP.NET files, clean up my GAC, as well as nuke all current assembly references in my project, clean solution, re-add required references, and finally clean and rebuild. I'm still not clear on why exactly VS2010 was referring to assemblies from an old build (simply cleaning and rebuilding is not enough). I also don't know at what point the environment stops "refreshing" and decides to simply refer to obsolete builds. I'll try to do a bit more research on this point and then add on to this post.

Modifying T4 code templates for ASP.NET MVC to get rid of full namespace reference

We're using (there is need to tell where the files are, thanks) custom T4 code templates on creating a view or controller. Default implementation makes this kind first row.
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ProjectNameHere.ViewModels.ViewModelClass>" %>
We have already ViewModel and MVC namespace defined in the Web.config, so I would like code template to generate this.
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="ViewPage<ViewModelClass>" %>
Any suggestions how modify the default templates to get that kind of results? Which of the template lines actually generate these?
More information
I know where the files are and modifications has been made. Problem is that in the template they're using this
string mvcViewDataTypeGenericString = (!String.IsNullOrEmpty(mvcHost.ViewDataTypeName)) ? "<" + mvcHost.ViewDataTypeName + ">" : String.Empty;
It seems that ViewDataTypeName contains full namespace reference. I would like get just name of the class (in this case ViewModel class name)
You can find the templates here:
*\Microsoft Visual Studio \Common7\IDE\ItemTemplates\CSharp\Web\MVC 2\CodeTemplates*
There you can edit the generated code for each template, the template lines vary for each template so i cannot tell you, but you will spot them immidiately.
EDIT
The source for Web.Extensions is not available, but you can make use of relector and reflect on
\Microsoft Visual Studio \Common7\IDE\Microsoft.VisualStudio.Web.Extensions.dll assembly to see what "mvcHost" gives you :)
You will then notice a ViewDataType property which is a "Type", and you should then be able to create some logic around it to get the class name.

Problems with Site.Master and ASP.NET MVC

i'm trying to make my site master page (views/shared/site.master) strongly typed.
eg. Inherits="TestProject.Mvc.Views.Shared.Site"
I can't seem to get this work. Once i make the site.master page strongly, typed, Visual Studio seems to 'loose' what <%= Html.XXX %> is. Also, the page throws an error when i try to display the default index route.
The SiteMasterViewData class exists in the views/shared/ folder and has been included at the top of the master page via..
<%# Import Namespace="TestProject.Mvc.Views.Shared"%>
Can this be done? is there a better way to do this?
Damn - found my own answer.
All masterpages in the ASP.NET MVC v1. need to inherit from:
<%# Master
Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage" %>
so if u want to strongly type it, you can do this.
<%# Master
Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage<SiteMasterViewData>" %>
HTH's other peeps :)

Resources