.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Extending RAZOR (functions, classic asp, .cs)

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net
 

Hi all,

First off... I really enjoy Web Matrix. I have already(very rapidly) created two locally host full fledged websites. These arent production ofcourse, but I was really impressed with how fast I was able to learn and build dynamic sites.

I want to learn more! I have some basic questions below;

  1. Can I call functions from a .cs to a .cshtml?
    Explained: Could I take an object oriented approach to RAZOR pages? If I were to create a class with some methods/functions/objects could I use them from my .cshtml?
    Does anyone have an example of this?

  2. Can I create functions inside a .cshtml page?
    Explained: Is this different from classic asp syntax?
    Should I be looking at classic asp syntax to learn more?

  3. If I wanted to create my own "helper" functions and/or add to the RAZOR api - is this something that is open?
    Explained: I'd love to be able to create my own set of "things" that I can continue to use in further projects?
    Yes? No?


  4. There are no clear examples or clear case usage of the html GET capability. Again, should I consider classic asp syntax for this?

  5. What will RAZOR be like down the road? Is there a goal?



View Complete Post


More Related Resource Links

Extending RAZOR

  

can you define function in a file and use it in another file ?

well , i managed to do it , but there may be an easiest way. I was able to define functions in _init , but not in the _start file :

@// _init.cshtml
@functions{

    string SaySomething()
    {
        return "Outside function calls work too !!!";
    }

}
@{


PageData["SaySomething"] =(Func<string>)SaySomething;
}


function call is simple : PageData["SaySomething"]()

but there may be a built in way and a way to declare functions in the APP_CODE folder in Razor syntax , isnt it ? (i'm full aware of C classes , but i wanted to try to do a 100% razor site , for study purposes )


Extending RAZOR

  

can you define function in a file and use it in another file ?

well , i managed to do it , but there may be an easiest way. I was able to define functions in _init , but not in the _start file :

@// _init.cshtml
@functions{

    string SaySomething()
    {
        return "Outside function calls work too !!!";
    }

}
@{


PageData["SaySomething"] =(Func<string>)SaySomething;
}


function call is simple : PageData["SaySomething"]()

but there may be a built in way and a way to declare functions in the APP_CODE folder in Razor syntax , isnt it ? (i'm full aware of C classes , but i wanted to try to do a 100% razor site , for study purposes )


Insert value using Table Value Functions

  
a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Introduction to Functions

  
A function is a section of code that is used to perform an isolated assignment. Once it has performed its assignment, the function can be accessed to present its result(s).

In Transact-SQL, a function is considered an object. After creating the function object, it becomes part of a database. You can then execute it when necessary.

Built-In Functions Fundamentals

  
While your primary job as a database developer consists of creating lists, probably your second most important job is to assist your users with the various assignments they must perform on your application. One way you can assist is to use functions that perform otherwise complex tasks. We introduced and described functions in the previous lesson. To assist your development with the different tasks of a database, Transact-SQL ships with various already created and tested functions. You just need to be aware of these functions, their syntax, and the results they produce.

Business Modelling and Web Applications and extending UML

  
UML can be used to model a business, prior to automating it with computers. The same basic UML syntax is used, however, a number of new symbols are added, in order to make the diagrams more relevant to the business process world. A commonly-used set of these symbols is available in current versions of Rational Rose.

Built-in Functions - Text and Image Functions in SQL Server

  
Text and image functions operate on TEXT, NTEXT and IMAGE data types. These data types are deprecated with SQL Server 2005 and should be replaced by VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) when possible. Alternatively you can also consider storing large string values using XML data type. Text and image functions are nondeterministic.

Future versions of SQL Server will not support TEXT, NTEXT and IMAGE data types. Columns with TEXT / NTEXT data type do not support commonly used string functions such as LEN, LEFT, RIGHT, etc. Furthermore, due to the large size of TEXT data you''re likely to see performance issues if you store such data in the database. However, at times you can''t help but use the TEXT / NTEXT / IMAGE data types (for example when supporting 3rd party databases when you cannot change the schema) - this is when text and image functions come in handy.

Date and Time Functions in SQLSERVER

  
Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

1 DATEPART Function
2 DATENAME Function
3 DAY, MONTH, and YEAR Functions
4 GETDATE and GETUTCDATE Functions
5 DATEADD Functions
6 DATEDIFF Function
7 More SQL Server Functions

Built-in Functions - Aggregate Functions

  
Aggregate functions return a single value summarizing a given data set. All aggregate functions are deterministic. NOTE: AVG, SUM, STDEV, STDEVP, VAR and VARP functions cannot operate on BIT data types; they can operate on all other numeric data types.

Built-in Functions - Date and Time Functions

  
Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

Cursor Functions

  
A cursor allows looping through a record set and performing a certain operation on each record within the set. SQL Server supports three functions that can help you while working with cursors: @@FETCH_STATUS, @@CURSOR_ROWS and CURSOR_STATUS. Cursor functions are non-deterministic.

Built-in Functions - String Functions

  
String functions let you extract various portions of character strings, change the case of strings, concatenate and reverse strings and perform many other types of manipulations. All built-in string functions are deterministic with the exception of CHARINDEX and PATINDEX

Built-in Functions - Text and Image Functions

  
Text and image functions operate on TEXT, NTEXT and IMAGE data types. These data types are deprecated with SQL Server 2005 and should be replaced by VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) when possible. Alternatively you can also consider storing large string values using XML data type. Text and image functions are nondeterministic.

User Defined Functions in Microsoft SQL Server

  
User Defined Functions are compact pieces of Transact SQL code, which can accept parameters, and return either a value, or a table. They are saved as individual work units, and are created using standard SQL commands. Data transformation and reference value retrieval are common uses for functions. LEFT, the built in function for getting the left part of a string, and GETDATE, used for obtaining the current date and time, are two examples of function use. User Defined Functions enable the developer or DBA to create functions of their own, and save them inside SQL Server.

Essential SQL Server Date, Time and DateTime Functions

  
The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all.

Date and Time Data Types and Functions

  
The following sections in this topic provide an overview of all Transact-SQL date and time data types and functions. For information and examples that are common to date and time data types and functions

Pocket TV Classic

  
PocketTV Classic is a Free software application that allows you to playback the common standard MPEG-1( .mpg) files on your Windows Mobile Pocket PC or other smartdevice. It is optimized to make use of the latest video acceleration hardware "2700G, ATI" and can playback videos in VGA resolution on VGA Pocket PC's I.E. Axim x51v/x50v, iPaq hx4700, Toshiba e800. A great tool to add to anyones collection.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend