using asp:input renders as a submit element, however it is possible to change this behavior so that it gets rendered as a button instead by setting the UseSubmitBehavior attibute to false.
<asp:Button runat="server" ID="buttonID" UseSubmitBehavior="false"/>
In order to convert a nullable Integer to a Interger, all that needs to be done is to call the GetValueOrDefault function of the nullable Type.
Dim intNullable As Integer? = Nothing
Dim int As Integer = intNullable.GetValueOrDefault()
In order to convert a Integer to a nullable interger, all that needs to be done is to call CType
Dim int As Integer = 0
Dim intNullable As Integer? = CType(int, Integer?)
VisualStudio 2012 assumes we are using the latest and greatest (version 2) when it comes to the Razer view engine. However when we are opening a project that was created using version 2010 then we were using 1.0 and that is the reason that 2012 is telling us about all the errors it believes we have with our project.
The solution is to edit the web.config file and under “appSettings” tell VisualStudio that this project is using version 1.0
<add key="webpages:Version" value="1.0" />
In order to store Binary data in a table, all that is needed is to upload the bytes from the file, one way to do this is to use File.ReadAllBytes
Dim fileName As String = "C:\testfile.txt"
dbCommand = New SqlCommand("UPDATE FileTable SET BinaryFile=@BinaryFile WHERE FileId = @FileId", dbConnection)
In order to get the Directory the application is running from we can use the AppDomain.CurrentDomain.BaseDirectory property
Dim runningFrom As String = AppDomain.CurrentDomain.BaseDirectory
This is similar to matching a name space with a wildcard.
'This is the node we are searching in
Dim someXmlNode As XmlNode = FetchXmlNode()
Dim xPathExpr As String = String.Empty
'find all nodes with names that starts with nisse_
xPathExpr = ".//*[starts-with(name(), 'nisse_')]"
'loop through all elements that matches our XPath
For Each elementWithNisse As XmlNode In someXmlNode.SelectNodes(xPathExpr)
.NET framework’s XslCompiledTransform only supports XPath and XSLT 1.0.
With XPath 1.0 ‘*’ is allowed to select all elements and nisse:* is allowed to select all elements in the namespace bound to the prefix ‘nisse’ but *:nisse to select ‘nisse’ elements in all
namespaces is not allowed in XPath 1.0, see http://www.w3.org/TR/xpath#node-tests.
And here is an example in vb.net where InnerText is read from the nameOfElementToFind in any name space
' This is the xmlnode the search is done with
Dim node As XmlNode = FetchSomeNode()
Dim innerTextFromNode As String = String.Empty
Dim xPathToSearchFor As String = String.Empty
'Will find all direct decendants nameOfElementToFind in any name space
xPathToSearchFor = "*[local-name() 'nameOfElementToFind']"
'Will find all nameOfElementToFind in any name space and anywhere under this node
xPathToSearchFor = ".//*[local-name() 'nameOfElementToFind']"
'Will find all nameOfElementToFind in any name space and anywhere in the document the node belongs to
xPathToSearchFor = "//*[local-name() 'nameOfElementToFind']"
If (node IsNot Nothing) Then
innerTextFromNode = node.selectSingleNode(xPathToSearchIn).InnerText
The RedicrectToAction simply generates a HTTP 302 code witch tells the browser to get the next page.
It is important to remember that when this is used inside a view then we should return RedicrectToAction. This will render the View to the client (and make it redirect) and will stop any further execution (if the RedirectToAction for instance is inside a if statement)
public ActionResult Upload(UploadOrderModel uploadorder)
//somthing fishy is going on ...
return RedirectToAction("Index", "Home");
//do important things here
system.web.mvc.controller.redirecttoaction at msdn