asp.net Core 1 RenderPartial ViewDataDictionary - asp.net-core-1.0

I am re-writing a website in VS 2017 that was originally written in VS 2010. The command I used originally to display my visitor count in the footer was:-
#Html.RenderPartial( "/Counter/Counter.ascx", new ViewDataDictionary {{ "digits", 6 }, { "id", "Count" }}). This displayed the number in Count.txt as 6 digits using digits.gif as the pattern. When I try and use the same code in VS 2017, I get the following error message: 'ViewDataDictionary' does not contain a constructor that takes 0 arguments. I have spent a lot of time looking at similar questions in this forum and on other sites and have been unable to find an answer. Any help you can give me will be most appreciated.

Another way to use this is to pass the ViewData of the current view into the constructor. That way the new ViewDataDictionary gets extended with the items you put in using the collection initializer.
#Html.Partial("MyPartial", new ViewDataDictionary(ViewData) { { "digits", 6 } })

When i went to implementation of the ViewDataDictionaryo:
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
public ViewDataDictionary(IModelMetadataProvider metadataProvider,
ModelStateDictionary modelState);
}
Possible solution
new ViewDataDictionary(
new Microsoft.AspNetCore.Mvc.ModelBinding.EmptyModelMetadataProvider(),
new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary())
{{ "digits", 6 }, { "id", "Count" }}

Related

Index Beyond Bounds / EXC_BAD_ACCESS upon Core Data Delete SwiftUI

I'm getting a Index Beyond Bounds error and a Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) when trying to delete a Core Data index in SwiftUI.
Basically, I have a Core Data entity (Dates), containing only a date attribute (Constraint - String). This has a one-to-many relationship with my Records Entity. I am trying to display a list of all date's I have. Displaying is fine, but upon trying to delete it, my app crashes.
My View currently looks as following:
import SwiftUI
struct Settings: View {
#Environment(\.managedObjectContext) var managedObjectContext
#FetchRequest(entity: Dates.entity(), sortDescriptors: []) var dates: FetchedResults<Dates>
var body: some View {
VStack {
List{
ForEach(dates, id: \.self) { day in
Text("\(day.wrappedDate)")
}.onDelete { (indexSet) in
let dateToDelete = self.dates[indexSet.first!]
self.managedObjectContext.delete(dateToDelete)
do {
try self.managedObjectContext.save()
} catch {
print(error)
}
}
}
}
}
}
I've broken my view down to the bare minimum to see if that would help, but unfortunately not.
When trying to delete. The error I get in the output is:
2020-04-29 16:08:23.980755+0300 TESTTEST[28270:2245700] [General] *** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray
If I have say 9 dates, it would say index 8 beyond bounds [0 .. 7], so it's not necessarily related to an empty Array.
Further output is:
=== AttributeGraph: cycle detected through attribute X ===
a bunch of times, followed by:
Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
on my AppDelegate.
Could the issue be in generating the view - rather than the delete?
Please be aware that I'm a self-taught, absolute Noob when it comes to coding, so I might be missing something obvious here. Any help on getting to the answer myself in the form of instructions would also be greatly appreciated (so I can learn how to fix this).
EDIT:
I think I found out what's causing the issue. In another view I'm also generating a list of all dates , where I apply an index on Dates. Will amend code now to see if this fixes it....
TBC!
In a separate view I was calling a list of dates in the following way:
ForEach(0 ..< self.dates.count, id: \.self) { index in
Text("\(self.dates[index].date)")
}
Deleting one of the Date entities, would mess up the indices presented in this view. Changing this structure to the below fixed the issue:
ForEach(self.dates, id: \.self) { day in
Text("\(day.date)")
}

How to override template file item-list.html.twig for field_slider_images in Drupal 8?

I want to override the item listing template file core/themes/classy/templates/dataset/item-list.html.twig for listing the fields field_slider_images as well as field_blog_tags respectively of their's multiple values of the field.
I have selected "Unordered List" in the view.
Please do check the attached image.
I have created following files :
item-list--field-blog-tags.html.twig
item-list--field-slider-images.html.twig
But, this is not rendered for the listing of the fields.
When I have created item-list.html.twig then only it will access.
However, both fields have different data to style and I am not able to get the current field name which is loading it's data in item-list.html.twig.
Had a brief look at this and it doesn't seem that 'item-list' to have suggestions, which is quite unfortunate.
In this situation there are two options:
Create your own suggestion which would accomplish exactly what you need.
You'll have to do something like this:
/
/*add new variable to theme with suggestion name*/
function hook_theme_registry_alter(&$theme_registry) {
$theme_registry['item_list']['variables']['suggestion'] = '';
}
//send a value to newly added variable to use it build the suggestion
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#suggestion'] = 'field_slider_images';
}
//use newly added variable to build suggestion
function hook_theme_suggestions_THEME_HOOK(array $variables) {//THEME_HOOK=item_list
$suggestions = array();
if(isset($variables['suggestion'])){
$suggestions[] = 'item_list__' . $variables['suggestion'];
}
return $suggestions;
}
Now you should be able to use item-list--field-slider-images.html.twig
Second option is to do what others in core did: use a new theme
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#theme'] = array(
'item_list',
'item_list__field_slider_images',
);
}

sharepoint 2013 visual studio workflow listitem dynamicvalue - get field value

this is what I did so far:
I'm using LookupSPListItem to get the current listItem out of the currentList.
The Result value is of type DynamicValue.
So far so good.
But how do I access specific values inside the resulting DynamicValue variable?
Unfortunately debugging my workflow doesn't work for some reasons... so I cannot have a look at the variable :(
I do not want to extract every single field on its own... that's too much work.
To access specific properties inside DynamicValue variable depends on the JSON structure it has parsed. But for example if you had something as below:
{
"d" : {
"results" : [
{ "Title" : "Example1" },
{ "Title" : "Example2" }
]
}
}
You can access those using the GetDynamicValueProperty activity (type Microsoft.Activities.dynamicValue) with
PropertyName as "d/results(1)/Title"
Source as your dynamic variable
Result with the variable you want to save the output to.
With the above query it would return Example2. In your case the result will be 1 element array, so you can query for example ID using "d/results(0)/ID"

How do I perform a MOSS FullTextSqlQuery and filter people results by the Skills managed property?

I am having trouble with a MOSS FulltextSqlQuery when attempting to filter People results on the Skills Managed Property using the CONTAINS predicate. Let me demonstrate:
A query with no filters returns the expected result:
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
Result
Total Rows: 1
ACCOUNTNAME: MYDOMAIN\Bob
SKILLS: Numchucks | ASP.Net | Application Architecture
But when I append a CONTAINS predicate, I no longer get the expected result:
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
And (CONTAINS(Skills, 'Numchucks'))
Result
Total Rows: 0
I do realize I can accomplish this using the SOME ARRAY predicate, but I would like to know why this is not working with the CONTAINS predicate for the Skills property. I have been successful using the CONTAINS predicate with a custom crawled property that is indicated as 'Multi-valued'. The Skills property (though it seems to be multi-valued) is not indicated as such on the Crawled Properties page in the SSP admin site:
http:///ssp/admin/_layouts/schema.aspx?ConsoleView=crawledPropertiesView&category=People
Anyone have any ideas?
So with the help of Mark Cameron (Microsoft SharePoint Developer Support), I figured out that certain managed properties have to be enabled for full text search using the ManagedProperty object model API by setting the FullTextQueriable property to true. Below is the method that solved this issue for me. It could be included in a Console app or as a Farm or Web Application scoped Feature Receiver.
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Administration;
private void EnsureFullTextQueriableManagedProperties(ServerContext serverContext)
{
var schema = new Schema(SearchContext.GetContext(serverContext));
var managedProperties = new[] { "SKILLS", "INTERESTS" };
foreach (ManagedProperty managedProperty in schema.AllManagedProperties)
{
if (!managedProperties.Contains(managedProperty.Name.ToUpper()))
continue;
if (managedProperty.FullTextQueriable)
continue;
try
{
managedProperty.FullTextQueriable = true;
managedProperty.Update();
Log.Info(m => m("Successfully set managed property {0} to be FullTextQueriable", managedProperty.Name));
}
catch (Exception e)
{
Log.Error(m => m("Error updating managed property {0}", managedProperty.Name), e);
}
}
}
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
And (CONTAINS(Skills, 'Numchucks*'))
use the * in the end.
You also have a few more options to try:
The following list identifies
additional query elements that are
supported only with SQL search syntax
using the FullTextSqlQuery class:
FREETEXT()
CONTAINS()
LIKE
Source

SharePoint: How do I create a new list from a list template?

I've created a list template based on an Issue list and it is saved in the List Template Gallery. Now how do I create a new list based on this template?
string internalName = "MyListTemplateName";
SPListTemplate t = null;
foreach (SPListTemplate template in web.ListTemplates)
{
if (template.InternalName.Equals(internalName)
{
t = template;
break;
}
}
web.Lists.Add("nameoflist", "description", t);
I just encountered the same situation today.
I saved a list as a template and i wanted to use that template in a new list.
On Sharepoint 2013, go to Site Contents > Add an App >
Scroll down and you will see a page numbering saying that you are on page 1
Click on the second page and all your saved templates will be there
It probably just took a while for the timer job to fire.
The template eventually showed up as an option under Lists > Create > Tracking section after a few minutes.
I'm surprised that Johan Leino's answer is marked as useful multiple times as it doesn't work in this particular case. If you create a template yourself, web.ListTemplates does not store it and you won't be able to create the list. It's only working for out-of-the-box templates.If you want to create a list based on your custom template you need to do it this way:
SPListTemplateCollection listTemplates = web.Site.GetCustomListTemplates(web);
SPListTemplate listTemplate = listTemplates["MyCustomTemplate"];
Guid listId = web.Lists.Add("My New List Name", "My Description", listTemplate);
if (listId != null) { //all good }

Resources