Using Custom Controllers, Views and information in view pages with parse.com
I have been on the website and read through pages of documentation on how to implement a custom controller and so on, but i just cant get the hang of it in this example.
Basically i am trying to use the parse database from parse.com in my umbraco solution, and i have some MVC that gets all the in this properties on the database and shows them with knockout.
I have in my App_Code folder a file called UmbracoEvenHandlers.cs that can reroute my custom controller around the conventional umbraco pipeline and it looks like this
public class UmbracoEventHandlers : ApplicationEventHandler
{
private static void RegisterCustomRoutes()
{
RouteTable.Routes.MapRoute(
name: "PropertyController",
url: "Property/{action}/{id}",
defaults: new { controller = "Property", action = "ShowProperty", id = UrlParameter.Optional }); }
}
This is my Property.cs model NOTE: The property.cs file inhertits from the ParseObject
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Property/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: Property/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Property/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: Property/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
What i want to point out is the ShowProperty action that expects and id and the goes to parse and finds the information based on the id and the returns an object.
Problem is that on my Master.cshtml which is my layout page, i have this @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
and on my Property view i use this @inherits Umbraco.Web.Mvc.UmbracoViewPage<vurdernu.Models.Property>
this presents a problem, it keep getting an error telling me that the model that was sent to the dictionary is of type vurdernu.models.Property, but a type of Umbraco.Web.Models.RenderModel was expected, BUT if i remove the Layout = "Master.chtml" form my Property View it works, is there a way around this ?
Using Custom Controllers, Views and information in view pages with parse.com
I have been on the website and read through pages of documentation on how to implement a custom controller and so on, but i just cant get the hang of it in this example.
Basically i am trying to use the parse database from parse.com in my umbraco solution, and i have some MVC that gets all the in this properties on the database and shows them with knockout.
I have in my App_Code folder a file called UmbracoEvenHandlers.cs that can reroute my custom controller around the conventional umbraco pipeline and it looks like this
public class UmbracoEventHandlers : ApplicationEventHandler
{
private static void RegisterCustomRoutes()
{
RouteTable.Routes.MapRoute(
name: "PropertyController",
url: "Property/{action}/{id}",
defaults: new { controller = "Property", action = "ShowProperty", id = UrlParameter.Optional }); }
}
This is my Property.cs model NOTE: The property.cs file inhertits from the ParseObject
[ParseClassName("Property")]
public class Property : ParseObject
{
[ParseFieldName("seller")]
public Seller Seller
{
get
{
return GetProperty<Seller>();
}
set
{
SetProperty<Seller>(value);
}
}
[ParseFieldName("lat")]
public string Lat
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("long")]
public string Long
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("street")]
public string Street
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("streetnumber")]
public string StreetNumber
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("floor")]
public string Floor
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("side")]
public string Side
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("zipcode")]
public string ZipCode
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("city")]
public string City
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("state")]
public string State
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("country")]
public string Country
{
get
{
return GetProperty<string>();
}
set
{
SetProperty<string>(value);
}
}
[ParseFieldName("primarypicture")]
public ParseFile PrimaryPicture
{
get
{
return GetProperty<ParseFile>();
}
set
{
SetProperty<ParseFile>(value);
}
}
[ParseFieldName("mediafiles")]
public List<ParseFile> MediaFiles
{
get
{
return GetProperty<List<ParseFile>>();
}
set
{
SetProperty<List<ParseFile>>(value);
}
}
}
My PropertyController
public class PropertyController : Controller
{
// GET: Property
//public async Task<ActionResult> Index(string id)
//{
// var query = from property in new ParseQuery<Property>()
// where property.ObjectId.Equals(id)
// select property;
// var foundProperty = await query.FirstOrDefaultAsync();
// return View(foundProperty);
//}
// GET: Property/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: Property/Create
public ActionResult Create()
{
return View();
}
public ActionResult List()
{
return View();
}
public async Task<ActionResult> ShowProperty(string id)
{
var query = from property in new ParseQuery<Property>()
where property.ObjectId.Equals(id)
select property;
var foundProperty = await query.FindAsync();
return View();
}
public async Task<JsonResult> LoadProperties()
{
var query = from property in new ParseQuery<Property>()
where property.ObjectId != string.Empty
select property;
IEnumerable<Property> properties = await query.FindAsync();
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string propertyOutput = serializer.Serialize(properties);
propertyOutput = propertyOutput.Replace("\"Key\":", "");
propertyOutput = propertyOutput.Replace("\"Value\":", "");
return Json(properties);
}
// POST: Property/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Property/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: Property/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Property/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: Property/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
What i want to point out is the ShowProperty action that expects and id and the goes to parse and finds the information based on the id and the returns an object.
Problem is that on my Master.cshtml which is my layout page, i have this @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
and on my Property view i use this @inherits Umbraco.Web.Mvc.UmbracoViewPage<vurdernu.Models.Property>
this presents a problem, it keep getting an error telling me that the model that was sent to the dictionary is of type vurdernu.models.Property, but a type of Umbraco.Web.Models.RenderModel was expected, BUT if i remove the Layout = "Master.chtml" form my Property View it works, is there a way around this ?
Many Thanks in advance
is working on a reply...