Ive got a form posting back in razor however im a bit confused as to how i can send the data from the form to the umbraco database. Any ideas as usuall will be appreciated.
You would do this in the same way you would in any standard ASP.NET page. Razor is just standard C# code so you can call any methods you like in the .NET framework or in your own external libraries.
To be clear, though, are you wanting to store your data in a custom table within the Umbraco database? If so, I would personally write a class library in Visual Studio and then compile it and place the assembly in your /bin folder (it would make sense to put it in a unique namespace, too). In your class library write a (probably) static method that accepts the parameters for your form and then call this method from your Razor script (like you would do any other method). That way the logic is all in your class and not within your Razor file.
Note that Umbraco 4 has it's own SQL Helper class that abstracts away data access (since Umbraco can work with different databases). This is in umbraco.BusinessLogic.Application.SqlHelper
NB. You should also investigate using Umbraco Contour form builder. It makes creation of forms very easily and all data is stored in a database without the need for any programming. It's well wroth 99 EUR.
however that just generates a table and i want to style it in my own way. I was also hoping to reuse the razor code for writing to other sections of umbraco such as the content nodes.
Writing to the database from the Front End
Ive got a form posting back in razor however im a bit confused as to how i can send the data from the form to the umbraco database. Any ideas as usuall will be appreciated.
You would do this in the same way you would in any standard ASP.NET page. Razor is just standard C# code so you can call any methods you like in the .NET framework or in your own external libraries.
To be clear, though, are you wanting to store your data in a custom table within the Umbraco database? If so, I would personally write a class library in Visual Studio and then compile it and place the assembly in your /bin folder (it would make sense to put it in a unique namespace, too). In your class library write a (probably) static method that accepts the parameters for your form and then call this method from your Razor script (like you would do any other method). That way the logic is all in your class and not within your Razor file.
Note that Umbraco 4 has it's own SQL Helper class that abstracts away data access (since Umbraco can work with different databases). This is in umbraco.BusinessLogic.Application.SqlHelper
NB. You should also investigate using Umbraco Contour form builder. It makes creation of forms very easily and all data is stored in a database without the need for any programming. It's well wroth 99 EUR.
Well i was hoping to be able to write to the members database. Ive got an asp.net default form:
<script runat="server">
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
Roles.AddUserToRole(CreateUserWizard1.UserName, "SiteMembers");
}
protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e)
{
Response.Redirect("/members.aspx");
}
</script>
<asp:CreateUserWizard ID="CreateUserWizard1" OnContinueButtonClick="CreateUserWizard1_ContinueButtonClick" OnCreatedUser="CreateUserWizard1_CreatedUser" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"></asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"></asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
however that just generates a table and i want to style it in my own way. I was also hoping to reuse the razor code for writing to other sections of umbraco such as the content nodes.
You can use methods in the ASP.NET membership provider - see http://our.umbraco.org/wiki/how-tos/membership-providers
cheers ill have a play around.
is working on a reply...