I have a custom controller to send message. So I need to get the value of property field name and alias = "email", this will be used to send the email to.
this code below works
var id = umbraco.uQuery.GetNodeByUrl("/contact-us");
IPublishedContent root = Umbraco.TypedContent(id.Id);
return root.GetProperty("email", true).Value.ToString();
However the problem here is if the page name changes, the url will change and the code will break.
So how can I change the code above to get the current page id and insert it here (???);?
I think the code should be something like this:
IPublishedContent root = Umbraco.TypedContent(???);
return root.GetProperty("email", true).Value.ToString();
Any help will be apprecciated
Your solution will bring a problem if you have more than 1 'ContactUs' node, or none. Then you don't know which one is going to be get.
(Actually it's the first one found in the node tree, but then someone can change the order of them...)
Is your controller a Surface controller? You can just do this:
IPublishedContent currentNode = Umbraco.TypedContent(CurrentPage.Id)
Ok, I found the solution for my question.
var nodes = umbraco.uQuery.GetNodesByType("ContactUs");
if (nodes.Any())
{
IPublishedContent node = Umbraco.TypedContent(nodes.First().Id);
return node.GetProperty(property, true).Value.ToString();
}
Hope this will help somebody with the same problem.
Related
I want my SAPUI5 ODataModel to send OData requests of the form
https://<my-server>/<my-service>/<my-resource>?search='lalaland'
There are tons of examples how to add a filter with model.filter(new Filter(...)); but this is not what I want. Filtering means I directly address a certain property with a certain comparator. Searching means I address the resource in general and let the OData service decide which properties to search, and how.
The one thing that seems to be possible is:
model.bindRows(..., { "customData": {"search": "lalaland"}});
But this is also not what I want because that sets the search term once when the model is created, but cannot update it later on when the user enters.
Funnily, SAPUI5's own implementation of the SmartTable performs exactly the kind of query I want - but doesn't reveal a possibility how I could do that without a SmartTable.
Found one solution:
oList = this.byId("list"); // or oTable
oBindingInfo = oList.getBindingInfo("items"); // or "rows"
if (!oBindingInfo.parameters) {
oBindingInfo.parameters = {};
}
if (!oBindingInfo.parameters.custom) {
oBindingInfo.parameters.custom = {};
}
oBindingInfo.parameters.custom.search = sValue;
oList.bindItems(oBindingInfo);
However, I don't specifically like the bindItems part. Looks a bit over-the-top to require this to re-bind the whole entity set again and again. So leaving this question open in case somebody has a better idea.
You can use on bindItems or bindRows depending what control is, something like this:
oList = this.byId("list");
oList.bindItems({path: '/XXXX', parameters : {custom: {'search':'searchstring'}}})
Why does it has to be $search and not $filter?
The OData V4 Tutorial in SAPUI5's Demo Kit uses
onSearch : function () {
var oView = this.getView(),
sValue = oView.byId("searchField").getValue(),
oFilter = new Filter("LastName", FilterOperator.Contains, sValue);
oView.byId("peopleList").getBinding("items").filter(oFilter, FilterType.Application);
},
I want to use a table for navigation purposes. Therefore I use the following code (the table looks good, all datas are complete):
// Admin.view.xml View
<Table id="objectsTable" itemPress="onSelectionChange">
// Admin.controller.js Controller
onSelectionChange: function(event) {
// After call undefined
var partnerId = event.getSource().getBindingContext().getProperty("BUSINESS_PARTNER_ID");
// After call defined and correct
var objectId = event.getSource().getBindingContext().getProperty("ID");
var router = this.getOwnerComponent()
.getRouter();
router.navTo("adminDetails", {
partner: partnerId,
object: objectId
});
After debugging I found out, that the value objectIdis undefined (while ID is present). This causes the navigation to not work properly.
So I looked at the data source (oData), which looks as follows :
ID | BUSINESS_PARTNER_ID | ADDRESS | FILES (oData association/navigation) |
.... All records are available, including the BUSINESS_PARTNER_ID
Why is the variable BUSINESS_PARTNER_IDundefined while all the data from the records are displayed correctly? I can query it, except BUSINESS_PARTNER_ID. Does anybody know how I can fix this?
Do partnerId and objectId have values? If the values for these are there then we need to check the routing and your manifest files. If partnerId and ObjectId are blank.
If these fields are blank i can think of another fix. Instead of binding the event from table, i believe you must have a columnlistitem or objectlistitem under your table. You can assign the press event on that and move this code to that.
Basically i am triggering the event from list item instead of table.
Thanks and Regards,
Veera
"Just" change my query to
event.getParameter("listItem").getBindingContext().getProperty("XYZ");
I have a single Umbraco 7 instance that has 2 root nodes. One node points to stage.sctflash.com and the other node points to stage.bullydog.com. When I navigate to http://stage.bullydog.com/Products/accessories/podmount, the Request.Url.Host is stage.bullydog.com. Now, if I open up another tab and go to http://stage.sctflash.com/Products/accessories/podmount, the Request.Url.Host might be stage.sctflash.com, but sometimes, it just changes to stage.sctflash.com.
The one strange thing I noticed is that if I view the accessories node in Umbraco, I noticed the parent of it is stage.bullydog.com no matter if I am on stage.sctflash.com or stage.bullydog.com
I am using Request.Url.Host to determine as a query parameter to a database. I am basically getting the brand like this:
if(Request.Url.Host == "stage.sctflash.com")
return "sct";
else
return bullydog";
So essentially if Request.Url.Host is intermittently wrong, I get the wrong query parameter.
To see this in action, if you go to http://stage.sctflash.com/Products/accessories/podmount, you will see an SCT logo, then go to http://stage.bullydog.com/Products/accessories/podmount and you will see a Bully Dog logo. These logos are driven by Request.Url.Host. If you refresh http://stage.sctflash.com/Products/accessories/podmount, you most likely will see the Bully Dog logo now because Request.Url.Host is now stage.bullydog.com instead of stage.sctflash.com
This is the action method that is called when I go to this page: http://stage.sctflash.com/Products/accessories/podmount
public ActionResult GetAccessoriesByType(RenderModel model, string id)
{
string brand = Common.GetProductBrand(Request.Url.Host);
var productSearchResultsModel = new ProductSearchResultsModel
{
Accessories = _accessoryRepository.GetAccessoriesByType(id, brand)
};
return View("~/Views/accessories.cshtml", productSearchResultsModel);
}
I came across a strange problem in my project today: I use this action throughout my website to generate breadcrumbs for a given page:
#Html.Action("BreadcrumbsWithHeader2", "SharedElements", new { pageName = #Model.pageName, department = #Model.department, menuHeading = #Model.menuHeading, id = "EandTHeader" })
Where it just returns a PartialView. This works great on every page except for one, where it began throwing this error:
No route in the route table matches the supplied values.
I've checked for things like spelling errors, etc., but am not sure how to debug this any further. What could cause something in the route table to go missing?
Edit: I've just noticed that any and all ActionLinks on the website pointing to this page (not the #Html.Action shown above, but rather the view where I call this partial) are producing blank href tags. The controller for it (if this helps) is here:
[Route("JobFair/FindAJobFair/{area}")]
public ActionResult FindAJobFair(string area, string sideMenu)
{
ViewBag.sideMenu = sideMenu;
JobFairsViewModel jobFairInfo = new JobFairsViewModel()
{
department = "Foo",
menuHeading = null,
pageName = "Job Fairs"
};
return View(jobFairInfo);
}
This route is typical of what I use elsewhere on the site (attribute routing).
Do you always provide a value for sideMenu? If you don't that may cause your problem. Try to modify your controller like this:
[Route("JobFair/FindAJobFair/{area}")]
public ActionResult FindAJobFair(string area, string sideMenu = null/*default value*/)
{
ViewBag.sideMenu = sideMenu;
JobFairsViewModel jobFairInfo = new JobFairsViewModel()
{
department = "Foo",
menuHeading = null,
pageName = "Job Fairs"
};
return View(jobFairInfo);
}
Hopefully this answer helps someone in the future - the problem had to do with my variable name area that was passed into the controller. Since my project has an 'Areas' folder it was causing an issue with routing. I simply needed to change area to something like region and the issue was solved.
I'm localising a site via a Change Language control in the master page. I need to render the control with the current url you're on in each of the different languages.
So if you're on http://site.com/en/Home/About and you change the language to french, I need to direct you to http://site.com/fr/Home/About.
The localisation code works on the route data language property, so I've been trying to figure out how I can:
Get access to the current action (with all original parameters)
Get the url to the current action (with all original parameters) with the route data changed.
Can anyone point me in the right direction?
I've tried passing the ViewContext from the parent into the UserControl, which gives me access to the route data but I can't figure out how to get the language routed url from that.
I ran this on the site I'm working on locally and it seemed to work. There's probably a cleaner way.
HttpRequestBase hrb = HttpContext.Request;
System.Uri url = hrb.Url;
string[] test = url.AbsoluteUri.Split('/');
int nIndex = 0, nCounter = 0;
foreach(string str in test)
{
if (str.Contains("site.com"))
{
nIndex = nCounter;
break;
}
nCounter++;
}
string strLanguage = test[nIndex + 1];
Obviously the +1 can even go in the IF statement, but I didn't think it looked good there. Hope this helps some.
I'm not 100% happy with this, I haven't got to a stage where I can fully test the impact of this but this is what I'm going for so far. Please do answer if you have a better solution.
I pass the ViewContext from the masterpage so I get the ViewContext with route data from whatever url you're currently on.
private string GetLocalisedUrl(ViewContext viewContext, string language)
{
viewContext.RouteData.DataTokens[LANGUAGE_ROUTEDATA_KEY] = language;
UrlHelper helper = new UrlHelper(viewContext.RequestContext);
return helper.Action(viewContext.RouteData.Values["action"].ToString(), viewContext.RouteData.Values["controller"].ToString(), viewContext.RouteData.DataTokens);
}