Sitecore Glassmapper Fields not editable - model-view-controller

Hi I am new to glassmapper and i am trying to create a simple view rendering.
While the view works, i am not able to edit it in experience editor. Is there like a setting that i should turn on???
My View is as simple is this:
#inherits Glass.Mapper.Sc.Web.Mvc.GlassView<sample.Web.Models.sampleclass>
#if (Model != null)
{
<div>
#Editable(Model,x=>x.Title)
</div>
}
My Modal:
using Glass.Mapper.Sc.Configuration.Attributes;
using System;
namespace Sampple.Web.Models.Sampleclass
{
[SitecoreType(TemplateId = "{FE05DA0F-7E18-47F8-AB77-F0ED7A0F9F90}",AutoMap = true)]
public class Sampleclass
{
[SitecoreId]
public virtual Guid Id { get; set; }
public virtual string Title{ get; set; }
[SitecoreField("Page Content")]
public virtual string Body{ get; set; }
}
}
I am able to see the content. It just that it is not editable when i open
http://mysite/?sc_mode=edit
Sidenote: i have changed the class names for explanation. Please ignore any typos

I this fixed?
If not, try below options:
When you open Sitecore Item in Experience Editor and when clicked on any field you must see those fields highlighted as in below screen shots, Then try to edit it within that highlighted area
Screen Shot 1
Screen Shot 2
if you are at the right place and if it is till not working. Can you check Sitecore Logs if there are any errors recorded.
Looking at the code it looks like you missed to map "Title" field.

Related

Problem in refreshing picker's item xamarin forms

I have a problem in refreshing the picker's UI in my Android.
I have two picker Province and Town.
If I select an item in province picker the town picker should refresh it content base on the selected province.
Therefore to do that I need to refresh my List of Town in my view model. which I successfully did each time I select a province.
The problem is the changes in my List of Town doesn't update or reflect on my Town's Picker when it run to my android emulator.
Any Idea?
One more thing, if I press the back button so to navigate to previous page. Then load the registration page again. The content of List of Town is successfully reflected to Town's Picker. It seems that it only bind my town picker in initialisation of my registration page. But once initialised it does not care whether you update the content of town in view model.
the problem is the changes in my List of Town doesn't update or reflect on my Town's Picker
What method did you use to update the picker? Try to detect the SelectedIndexChanged event of the province Picker, update the ItemsSource of town Picker in this method.
Check the code:
<StackLayout>
<Picker Title="select the Province" x:Name="ProvincePicker" ItemsSource="{Binding provinces}" ItemDisplayBinding="{Binding ProvinceName}" SelectedIndexChanged="ProvincePicker_SelectedIndexChanged"></Picker>
<Picker Title="select the Town" x:Name="TownPicker" ItemDisplayBinding="{Binding TownName}"></Picker>
</StackLayout>
Page.xaml.cs
public Page5()
{
InitializeComponent();
var province_data = new ObservableCollection<_Province>()
{
//add the data
};
CityViewModel cityViewModel = new CityViewModel();
cityViewModel.provinces = province_data;
BindingContext = cityViewModel;
}
private void ProvincePicker_SelectedIndexChanged(object sender, EventArgs e)
{
CityViewModel viewModel = BindingContext as CityViewModel;
var picker = sender as Picker;
TownPicker.ItemsSource = viewModel.provinces[(picker).SelectedIndex].towns;
}
The code of model class
public class _Town
{
public string TownName { get; set; }
}
public class _Province
{
public string ProvinceName { get; set; }
public ObservableCollection<_Town> towns { set; get; }
public _Province()
{
towns = new ObservableCollection<_Town>();
}
}
public class CityViewModel
{
public ObservableCollection<_Province> provinces { get; set; }
public CityViewModel()
{
provinces = new ObservableCollection<_Province>();
}
}

Values changed in inputs on one tab are echoed and overwrite values on other tabs

I've got an MVC CORE/Entity Framework CORE project with some Razor pages. On the Razor pages, if I've got the same page open in two tabs/browsers, changing the inputs on one, change the inputs on the other. So, if in one tab I'm editing book 345
http://localhost:12345/books/edit/345
and in another I'm editing 456
http://localhost:12345/books/edit/456
if I'm editing the Title text box on 345, as I type, the same values are echoed on the Title text box on 456. The same is true for all inputs, drop downs, text/numeric input boxes, checkboxes, etc. Saving commits whatever's in the inputs to the record.
Any ideas why? I've not added any code as I'm not sure which'd be most relevant and don't want to dump the entire project here.
Edited for code based on comments
private readonly MyModels.MyContext _context;
public EditModel(MyModels.MyContext context) : base(context) {
_context = context;
}
[BindProperty]
public BookModel objRecord { get; set; }
This is the top of the Razor page's code behind, with the constructor and bound property
#page "{BookID?}"
#model myProject.Pages.Books.EditModel
This is the top of the .cshtml page.
In startup.cs
in
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ForceGateway.Models.ForceGatewayContextModel contextM) {
I've got
if (env.IsDevelopment()) {
app.UseBrowserLink();
UseBrowserLink links browsers to each other as well as to Visual Studio t'would appear.

Click in a children in a custom xamarin forms layout

I have this class derived from a Layout<view> which is the WrapLayout example from Creating a Custom Layout:
Tthe code is a little big, so I put it in this pastebin:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace CustomLayout.ViewModels
{
// ...
// [EDIT] puting the relevant code for put the images whit
/// a tap gesture in the layout
var images = GetImages();
int i = 0;
foreach (var photo in images.Photos)
{
var image = new Image
{
Source = ImageSource.FromResource(photo),
WidthRequest = 50,
HeightRequest = 75
};
var cartaoTap = new TapGestureRecognizer();
cartaoTap.Tapped += (s, e) =>
{
cartaoClick(i);
};
image.GestureRecognizers.Add(cartaoTap);
customLayout.Children.Add(image);
i++;
}
// ...
private void cartaoClick(int index){
Navigation.PushAsync(new CartaoPage(cartao.GetImagem(index), cartao.GetNome(index), cartao.GetDescricao(index)));
}
}
pastebin Raw Code for the CustomLayout class
"Cartao" is a class with attributes like Nome, Descricao and Imagem.
In the tap gesture event I pass the int "i" value to the CartaoClcik(int index) method when I added the image in the CustomLayout, in my mind, I can get the index passed to the call of this method when I added the image in the click of the mouse in one of the image showed, but, when I run and click in a image, the index parameter is alawys of the last image added
[EDIT:].
After an inhumane search job on the internet, I see that is possible to implement a class derived from Image() and then implement the GestureRecognizer command directly in this class, but I dont know how I can implement that and also I dont know how to pass the parameter needed for the page to show the image in full screen in the `CartaoPage(Image img, string nome, string descr) whose parameters have to be passed in when the user click in a image showed in they screen
someone can help me?
[SOLVED]
I solved this question, to solve I created a class derived from Image() with a public int ID {get; set;} and then fill this attribute when I instantiate my image using my own class and then I pass this ID for my index.
I know that not is a elegant solution but is working here.
thanks for all

Autogenerated outlet in designer.cs type of subclass

I want to know whether it's possible for Xamarin Studio to set the type of an autogenerated outlet in, say, myview.designer.cs to the sublcass of a control within the .xib.
For example, I've subclassed NSButton to create some custom UI for buttons throughout the app.
I have my class defined as something like this, using the Register attribute so it's visible to the Objective-C runtime:
[Register("AppButton")]
public class AppButton : NSButton
{
...
}
Within XCode, I have then set the custom class to AppButton on my NSButtons. If I open the .xib in a text editor, I can see the customClass attribute on my buttons:
<button id="bxh-qr-g81" ... customClass="AppButton">
But when Xamarin Studio has listened for the changes, and updated the designer file, I always seem to get the outlet with a type of NSButton instead of AppButton.
[Register ("MyView")]
partial class MyView
{
[Outlet]
AppKit.NSButton MyButton { get; set; }
...
}
I would like it to be the type of my custom class:
[Register ("MyView")]
partial class MyView
{
[Outlet]
AppButton MyButton { get; set; }
...
}
The main reason for this is that I want to set some properties within AwakeFromNib, and it's a little tedious to cast it every time. It would also be nice for the compiler to throw an error if the type changed, rather than a runtime error, assuming I don't check that it really is the type of AppButton.
If I could set the properties directly on my subclass within XCode, this wouldn't be an issue. But as far as I can tell, IBInspectable or IBDesignable doesn't seem to be supported by Xamarin.
I got this to work by:
Creating the subclass like below
Building Xamarin studio first
opening xcode check for CustomButton.h and CustomButton.m file
Set the class type in xcode it should appear in the drop down:
Creating the outlets again. should then look like this:
[Outlet]
AppName.iOS.CustomButton customButton { get; set; }
I think you mean UIButton too not NSButton
using System;
using UIKit;
using Foundation;
namespace EdFringe.iOS
{
[Register ("CustomButton")]
public class CustomButton : UIButton
{
public CustomButton ()
{
}
public CustomButton (IntPtr p) : base(p)
{
//this one i think is used to create the obj-c object.
}
public CustomButton (NSCoder coder) : base(coder)
{
// This one i think is used when creating the xib.
}
//Custom stuff here
}
}

using html.actionlink outside of a viewpage in MVC3

Struggling on in my first MVC project, I need to show a menu of steps for a wizard. The problem is that some of the steps depend on the data that the user provides.
So say for example, if a user pays cash, we skip the page that shows bank-account information (and thus remove the menu-item)..
I have a "page" class in C#, and a "menu" class that has a list of "pages". I'm going to write the logic that dictates whether or not to show a menu-item in the menu class.
The problem is this;
The page class is a very simple class that looks like this ("active" means the menuitem is highlighted as the currently active item):
public class Page
{
MvcHtmlString Link { get; set; }
bool Active { get; set; }
bool Visible { get; set; }
public Page(MvcHtmlString link)
{
Link = link;
Active = false;
Visible = true;
}
public Page(MvcHtmlString link, bool active, bool visible)
{
Link = link;
Active = active;
Visible = visible;
}
}
In my logic I want to add pages to the list, and I'd like to use the "Link" property of a page to store the target URL for each menu-item. This way I can fill that property using Html.Actionlink() and all its available parameters to generate the HTML for the link.
In the eventual menu I can just iterate and show the items.
It also has the advantage that I could do an AJAX call to this function and receive HTML back I can use in my page to update the menu dynamically.
However, Html.ActionLink is not available, and in other posts on Stackoverflow I found that people also dislike using a html helper outside of an MVC view, for understandable reasons.
So my question is; how would I go about this in a clean solution? I considered giving the page class not a Link property, but "controller" and "action" properties, but I would be missing out on the flexibility of adding a class or other HTML attributes easily, which the actionlink DOES provide.
Thanks,
Erik

Resources