Alternative to Onclick for Button function in Umbraco 8
Hi I have been developing in previous versions of Umbraco for quite a while.
In previous versions I had been using the macro's as a method of incorporating C# and .net into my pages.
I have been trying to get them to work for Umbraco 8, but the buttons have not been working as intended. I am aware that OnClick is no longer valid on the Razor code for the Partial View Macro. I have attempted to substitute this via Html.RenderPartial, IsPost and ActionResults however none of these have worked on Umbraco 8 as intended.
The Html.RenderPartial IsPost doesn't work because the page seems to cache data, so the c# only runs the first time after the code has published.
This happens across multiple machines.
The issue I have with ActionResults is that the return value keeps returning the error "The name 'View' does not exist in the current context". for the various valid ActionResult options.
Firstly i had been using action results wrong it is meant to go into the controller not the razor macro code space.
Second by using the code below i was able to pull the content from the page to set it up as new content.
To alter the page I added specific div's for splitting the page for where i wanted to add things.
(please note that the code is an altered version of example code for a simple submission. was given the code and do not know the original source.)
Code:
[System.Web.Mvc.HttpPost]
public ActionResult SubmitDemoForm(DemoFormViewModel model)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("Error", "Please complete all required fields");
}
System.Text.StringBuilder sbMessage = new System.Text.StringBuilder();
WebClient client = new WebClient();
var url = new Uri(Request.Url, Request.RawUrl);
string content = client.DownloadString(url);
string[] words = content.Split(new[] { "<div style = \"display:none;\">Split</div>\r\n" }, StringSplitOptions.None);
sbMessage.Append(words[0]);
sbMessage.Append("Your Name is : " + model.Name + "</br/>");
sbMessage.Append("Your Password is : " + model.TelephoneNumber + "</br/>");
sbMessage.Append("Your Email is : " + model.EmailAddress + "</br/>");
sbMessage.Append("</br/>");
for (int n = 1; n < words.Count(); n++)
{
sbMessage.Append(words[n]);
}
return Content(sbMessage.ToString());
}
Hopefully this can help other people having the same issue.
Alternative to Onclick for Button function in Umbraco 8
Hi I have been developing in previous versions of Umbraco for quite a while. In previous versions I had been using the macro's as a method of incorporating C# and .net into my pages.
I have been trying to get them to work for Umbraco 8, but the buttons have not been working as intended. I am aware that OnClick is no longer valid on the Razor code for the Partial View Macro. I have attempted to substitute this via Html.RenderPartial, IsPost and ActionResults however none of these have worked on Umbraco 8 as intended.
The Html.RenderPartial IsPost doesn't work because the page seems to cache data, so the c# only runs the first time after the code has published. This happens across multiple machines.
The issue I have with ActionResults is that the return value keeps returning the error "The name 'View' does not exist in the current context". for the various valid ActionResult options.
How can I resolve this?
Kind Regards
I have found a solution.
Firstly i had been using action results wrong it is meant to go into the controller not the razor macro code space.
Second by using the code below i was able to pull the content from the page to set it up as new content. To alter the page I added specific div's for splitting the page for where i wanted to add things.
(please note that the code is an altered version of example code for a simple submission. was given the code and do not know the original source.)
Code:
Hopefully this can help other people having the same issue.
is working on a reply...