Im currently following the surface controllers and API tutorial videos on the umbraco Tv website and Ive run into a minor problem. Im using Umbraco version 7.0.2 and I created a partial view in the partials folder but it did not show up in the back office in the drop down list to use with a macro.
So I tried to create it again but from the macropartial folder and this give me no build errors and it was available to select from the dropdown however when it renders it displays the following syntax
Could you try creating from the backoffice, new macro partial and have the checkbox create macro checked (that should create an associated macro), does that work?
Over the weekend I have stumbled on another query that Im also hoping you may be able to help with?
Is it possible to render a node from the backend that preserves the details that have previously been enetered by a user so they can be edited and re-saved?
For example (using the video on umbraco tv) if a user fills out their name, email, and message and then submits, a node with the values is created in the umbraco back office and saved and published. Now if the user (a member with access) wants to revist this page to edit the information (say email) they previously filled out, is it possible to do?
Sorry Tim I didnt realise you had replied whilst I was writing my other post out. Here is my code
Please note: The way I am trying to do this is so that every time a node is created the name in the back office needs to be dynamically named using the value taken from th pageName in the model.
so the nodes are not named
Venues comment comment(1) comment(2) etc.
But Named
Venues Hilton Holtel Beverly Hills Hotel The Ritz etc
//Here is my model code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace uFunction.Models
{
public class AddVenueModel
{
public string pageName { get; set; }
public string venueLocation { get; set; }
}
}
//view code - in the partials folder
@model uFunction.Models.AddVenueModel
@if(TempData["success"] == null)
{
Add a venue
using (Html.BeginUmbracoForm("HandleFormSubmit"))
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
using uFunction.Models;
using Umbraco.Web.Mvc;
namespace uFunction.Controllers
{
public class AddVenueSurfaceController : SurfaceController
{
//
// GET: /AddVenueSurface/
public ActionResult Index()
{
return PartialView("AddVenue", new AddVenueModel());
}
[HttpPost]
public ActionResult HandleFormSubmit(AddVenueModel model)
{
if (ModelState.IsValid)
return CurrentUmbracoPage();
// Create Venue
var newVenue = Services.ContentService.CreateContent("Venue", CurrentPage.Id, "Venue");
newVenue.SetValue("venueLocation", model.venueLocation);
Services.ContentService.SaveAndPublishWithStatus(newVenue);
//send admin email
//send email
MailMessage message = new MailMessage();
message.To.Add("[email protected]");
message.Subject = "New Venue on uFunction";
message.From = new System.Net.Mail.MailAddress("[email protected]");
message.Body = "You have a new venue entry on uFunction";
SmtpClient smtp = new SmtpClient();
smtp.Send(message);
TempData["success"] = true;
return RedirectToCurrentUmbracoPage();
}
}
Help with surface controllers & Macro Partials
Hi everyone,
Im currently following the surface controllers and API tutorial videos on the umbraco Tv website and Ive run into a minor problem. Im using Umbraco version 7.0.2 and I created a partial view in the partials folder but it did not show up in the back office in the drop down list to use with a macro.
So I tried to create it again but from the macropartial folder and this give me no build errors and it was available to select from the dropdown however when it renders it displays the following syntax
Error loading Partial View script (file: ~/Views/MacroPartials/AddVenue.cshtml)
How do I allow macros to use partials from the partials folder
Thanks
Paul
Comment author was deleted
Hey,
Could you try creating from the backoffice, new macro partial and have the checkbox create macro checked (that should create an associated macro), does that work?
Hi Tim,
Thanks for your reply mate.
I will give it a whirl and let you know the outcome ;)
Paul
Hi Tim,
I tried what you suggested and Im still not able to render the macro it keeps giving me the syntax
Error loading Partial View script (file: ~/Views/MacroPartials/AddVenue.cshtml)
Any suggestions where I could be going wrong?
Thanks
Paul
Comment author was deleted
Ok mind sharing what code you have in the addvenue.cshtml ? and confirm that the file exists in that location?
Hi Tim,
Over the weekend I have stumbled on another query that Im also hoping you may be able to help with?
Is it possible to render a node from the backend that preserves the details that have previously been enetered by a user so they can be edited and re-saved?
For example (using the video on umbraco tv) if a user fills out their name, email, and message and then submits, a node with the values is created in the umbraco back office and saved and published. Now if the user (a member with access) wants to revist this page to edit the information (say email) they previously filled out, is it possible to do?
member fills out the following info
Name = Paul
Email = [email protected]
Message = Hello World!
(Save) - a node is saved and published in the umbraco backend
Member logs on and visits the same page and instead of seeing a blank form they see current values being held by the node (from the previous commit)
Name = Paul
Email = [email protected]
Message = Hello World!
(Save) - The node in the umbraco back office is updated with the new values
Hope you understand what I mean here.
Thanks
Paul
Sorry Tim I didnt realise you had replied whilst I was writing my other post out. Here is my code
Please note: The way I am trying to do this is so that every time a node is created the name in the back office needs to be dynamically named using the value taken from th pageName in the model.
so the nodes are not named
Venues
comment
comment(1)
comment(2) etc.
But Named
Venues
Hilton Holtel
Beverly Hills Hotel
The Ritz etc
using System; using System.Collections.Generic; using System.Linq; using System.Web;
namespace uFunction.Models { public class AddVenueModel { public string pageName { get; set; } public string venueLocation { get; set; } } }
//view code - in the partials folder
@model uFunction.Models.AddVenueModel
@if(TempData["success"] == null) {
Add a venue
@Html.TextBoxFor(m => m.pageName, new { placeholder = "Venue Name" }) @Html.ValidationMessageFor(m => m.pageName) @Html.TextBoxFor(m => m.venueLocation, new { placeholder = "Venue Location" }) @Html.ValidationMessageFor(m => m.venueLocation)
}
else {
Thanks for your entry
}
//controller code
using System; using System.Collections.Generic; using System.Linq; using System.Net.Mail; using System.Web; using System.Web.Mvc; using uFunction.Models; using Umbraco.Web.Mvc;
namespace uFunction.Controllers { public class AddVenueSurfaceController : SurfaceController { // // GET: /AddVenueSurface/
}
Thanks again
Paul
Comment author was deleted
Ok looks good and what is the code in the addvenue.cshtml file?
Do you mean this code?
//view code - in the partials folder
@model uFunction.Models.AddVenueModel
@if(TempData["success"] == null) {
Add a venue
@Html.TextBoxFor(m => m.pageName, new { placeholder = "Venue Name" }) @Html.ValidationMessageFor(m => m.pageName)
@Html.TextBoxFor(m => m.venueLocation, new { placeholder = "Venue Location" }) @Html.ValidationMessageFor(m => m.venueLocation)
}
else {
Thanks for your entry
}
Comment author was deleted
Ok that will be the issue then, move it to partials and then create a new macro partial that renders that partial :)
Since a macro partial is a special kind of partial and that needs to inherit from something umbraco core related check
http://umbraco.tv/videos/developer/fundamentals/surface-controllers/using-surface-controllers-in-the-rte/
is working on a reply...