I am using monkey chat in my mobile application(Xamrin forms based). While sending a message on IOS, on a real device, I have to click the send button 2 times. First time when I click, it minimizes the keyboard and 2nd time, it sends the message. Please suggest.
How do I send a message on one click?
Here is my send message function
namespace Budocode.ViewModels
{
public class MainChatViewModel : BaseViewModel
{
public ObservableRangeCollection Messages { get; }
ITwilioMessenger twilioMessenger;
string outgoingText = string.Empty;
public string OutGoingText
{
get { return outgoingText; }
set { SetProperty(ref outgoingText, value); }
}
public ICommand SendCommand { get; set; }
public ICommand LocationCommand { get; set; }
public MainChatViewModel()
{
// Initialize with default values
twilioMessenger = DependencyService.Get<ITwilioMessenger>();
Messages = new ObservableRangeCollection<ChatMessage>();
SendCommand = new Command(() =>
{
var message = new ChatMessage
{
Text = OutGoingText,
IsIncoming = false,
ProfileId = "profile" + GlobalSettingsDataSource.Current.SelectedProfileImageId + ".png",
MessageDateTime = DateTime.Now,
FromUser = GlobalSettingsDataSource.Current.SelectedProfile
};
if (string.IsNullOrWhiteSpace(OutGoingText))
return;
Messages.Add(message);
twilioMessenger?.SendMessage(message.Text, message.ProfileId, GlobalSettingsDataSource.Current.SelectedProfile);
OutGoingText = string.Empty;
});
LocationCommand = new Command(async () =>
{
try
{
var local = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(15));
var map = $"https://maps.googleapis.com/maps/api/staticmap?center={local.Latitude.ToString(CultureInfo.InvariantCulture)},{local.Longitude.ToString(CultureInfo.InvariantCulture)}&zoom=17&size=400x400&maptype=street&markers=color:red%7Clabel:%7C{local.Latitude.ToString(CultureInfo.InvariantCulture)},{local.Longitude.ToString(CultureInfo.InvariantCulture)}&key=";
var message = new ChatMessage
{
Text = "I am here",
AttachementUrl = map,
ProfileId = "profile" + GlobalSettingsDataSource.Current.SelectedProfileImageId + ".png",
IsIncoming = false,
MessageDateTime = DateTime.Now
};
Messages.Add(message);
twilioMessenger?.SendMessage("attach:" + message.AttachementUrl, message.ProfileId, GlobalSettingsDataSource.Current.SelectedProfile);
}
catch (Exception ex)
{
}
});
if (twilioMessenger == null)
return;
twilioMessenger.MessageAdded = (message) =>
{
//if (message.ProfileId == "Icon.png")
Device.BeginInvokeOnMainThread(() =>
{
if (message.FromUser != GlobalSettingsDataSource.Current.SelectedProfile)
{
message.IsIncoming = true;
}
else
{
message.IsIncoming = false;
}
Messages.Add(message);
});
};
}
public async void InitializeMock(string channelName)
{
try
{
var id = CrossDeviceInfo.Current.Id;
var userId = PersistantData.Current.UserAccount.Properties["user_id"];
HttpResponseMessage appResponse = CommonUtility.GetApiContent(
String.Format(ClientConfiguration.TwilioServiceChatHistory, id, GlobalSettingsDataSource.Current.SelectedProfile, channelName));
if (appResponse.IsSuccessStatusCode)
{
var chatContent = await appResponse.Content.ReadAsStringAsync();
List<ChatMessage> chatMsgs = JsonConvert.DeserializeObject<List<ChatMessage>>(chatContent);
Messages.ReplaceRange(chatMsgs);
}
}
catch
{
// ignore if there are any issues with twilio
}
}
}
}
Related
I have tried for the last 4 days to find an illusive image in that app, I am new to xamarin forms and a client asked me to replace an image which I did, but I have left with another image that I should implement and I can't find its source, the XML code for the specific section looks like this.
<ScrollView Grid.Row="2"
HeightRequest="50"
HorizontalOptions="CenterAndExpand"
Orientation="Horizontal"
IsVisible="{Binding PhotosVisible.Value}"
x:Name="ScrollPhotos">
<StackLayout Orientation="Horizontal"
Spacing="0"
VerticalOptions="Center"
Padding="5,0"
x:Name="StackPhotos">
</StackLayout>
</ScrollView>
and the place I'm trying to implement the photo in is:
should be an image instead of the blank grey rectengle
(should be an image instead of the blank grey rectangle)
I cant find the source to the other image, and I even deleted something that was pretty similar in the drawAble folder but it changed nothing.
any help or suggestion will be helpful, Thanks. :)
edit:
The xml.cs source code:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DashboardPage : ExtPage
{
public DashboardPage()
{
InitializeComponent();
Padding = new Thickness(0, 0, 0, MashamAppForms.Helpers.Settings.NativeSetting.BottonPadding);
NavigationPage.SetHasBackButton(this, false);
}
protected override void OnAppearing() {
MessagingCenter.Subscribe<Application>(App.Current, "DashboardFillDates", FillDates);
MessagingCenter.Subscribe<Application, CPhoto[]>(App.Current, "DashboardFillPhotos", FillPhotos);
base.OnAppearing();
}
protected override void OnDisappearing() {
MessagingCenter.Unsubscribe<Application>(App.Current, "DashboardFillDates");
base.OnDisappearing();
}
void FillPhotos(Application arg1, CPhoto[] arg2) {
var bc = (DashboardViewModel)BindingContext;
StackPhotos.Children.Clear();
if (arg2 == null)
return;
foreach (var photo in arg2) {
var image = new CachedImage {
Aspect = Aspect.AspectFill,
Source = photo.Path,
BackgroundColor = Color.FromHex("#504F77AB"),
DownsampleHeight = 100,
HeightRequest = 40,
WidthRequest = 60,
Margin = new Thickness(5, 0)
};
Commands.SetTap(image, bc.ViewImageCommand);
Commands.SetTapParameter(image, photo);
StackPhotos.Children.Add(image);
}
Device.BeginInvokeOnMainThread(() => {
try {
ScrollPhotos.ScrollToAsync(StackPhotos.Children.LastOrDefault(), ScrollToPosition.End, false);
}
catch {
}
});
}
void FillDates(Application application) {
var bc = (DashboardViewModel)BindingContext;
var dates = bc.Dates;
StackDates.Children.Clear();
if (dates == null)
return;
for (var i = 0; i < dates.Length; i++) {
var t = dates[i];
var grid = new Grid {
RowDefinitions =
{
new RowDefinition {Height = GridLength.Star},
new RowDefinition {Height = GridLength.Star},
new RowDefinition {Height = GridLength.Star}
},
Padding = new Thickness(5, 0),
RowSpacing = 0,
BindingContext = t
};
grid.SetBinding(Grid.BackgroundColorProperty, "BackgroundColor.Value");
var l1 = new Label {
Text = t.HebrewDay,
TextColor = t.TextColor,
HorizontalOptions = LayoutOptions.Center,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
};
l1.SetBinding(Label.TextColorProperty, "TextColor.Value");
grid.Children.Add(l1, 0, 0);
var l2 = new Label {
Text = t.HebrewDate,
TextColor = t.TextColor,
HorizontalOptions = LayoutOptions.Center,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
};
l2.SetBinding(Label.TextColorProperty, "TextColor.Value");
grid.Children.Add(l2, 0, 1);
var l3 = new Label {
Text = t.Date.ToString("dd/MM/yyyy"),
TextColor = t.TextColor,
HorizontalOptions = LayoutOptions.Center,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
};
l3.SetBinding(Label.TextColorProperty, "TextColor.Value");
grid.Children.Add(l3, 0, 2);
var gest = new TapGestureRecognizer {
Command = bc.ChangeDateCommand,
CommandParameter = t
};
grid.GestureRecognizers.Add(gest);
StackDates.Children.Add(grid);
if (i != dates.Length - 1)
StackDates.Children.Add(new BoxView {
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Fill,
WidthRequest = 1,
Color = (Color)Application.Current.Resources["SelectionColor"]
});
}
Device.BeginInvokeOnMainThread(() =>
{
try {
ScrollDates.ScrollToAsync(StackDates.Children.LastOrDefault(), ScrollToPosition.End, false);
}
catch {
}
});
}
}
and the viewModel.cs is:
public class DashboardViewModel : FormsBaseViewModel
{
static bool _nowAsking;
static bool _scanning;
public ICommand ChangeDateCommand { get; }
public ICommand LogoutCommand { get; }
public ICommand ListHeaderCommand { get; }
public ICommand EventCommand { get; }
public ICommand QrCommand { get; }
public ICommand ViewImageCommand { get; }
public ICommand PhotoCommand { get; }
public ICommand FeedbackCommand { get; }
public ICommand LocationCommand { get; }
public ICommand ContactsCommand { get; }
public ICommand MessagesCommand { get; }
public ICommand FileCommand { get; }
public ObservableProperty<int> CarouselPosition { get; }
public ObservableProperty<BasePageState> EventsState { get; } = new ObservableProperty<BasePageState>();
public ObservableProperty<bool> IsBusy { get; } = new ObservableProperty<bool>();
public ObservableProperty<bool> PhotosVisible { get; } = new ObservableProperty<bool>();
public SmartCollection<EventDetails> EventList { get; set; }
public Conferance Conferance { get; set; }
public bool SubtitleVisible => !string.IsNullOrEmpty(Conferance?.SubTitle);
public string Phone { get; set; }
public string Name { get; set; }
public string RealId { get; set; }
public EventDetails[] Events { get; set; }
public QrDetails[] QrDetails { get; set; }
public CPhoto[] CPhotos { get; set; }
public string FileLink { get; set; }
public string Greeting { get; set; }
public string ApiKey { get; set; }
public CParticipant[] Participants { get; set; }
public ThreeDatesItem[] Dates { get; set; }
private ThreeDatesItem _selected;
public ThreeDatesItem SelectedDate
{
get => _selected;
set
{
_selected = value;
EventList.Clear();
Task.Run(async () =>
{
await Task.Delay(100);
EventList.AddRange(GetEvents(value.Date));
});
}
}
public DashboardViewModel()
{
CarouselPosition = new ObservableProperty<int>();
EventList = new SmartCollection<EventDetails>();
ChangeDateCommand = new Command<ThreeDatesItem>(item =>
{
foreach (var tdi in Dates)
{
tdi.IsSelected = false;
}
item.IsSelected = true;
SelectedDate = item;
});
LogoutCommand = new Command(async () =>
{
Settings.Authed = false;
Settings.SavedPhone = "";
Settings.SavedId = "";
OneSignal.Current.DeleteTag("confId");
await NavigationService.Navigate<LoginViewModel>();
NavigationService.ClearNavigationStack();
});
ListHeaderCommand = new Command<EventDetails>(details =>
{
var mainColor = (Color)Application.Current.Resources["SelectionColor"];
if (details.IsOpened)
{
var del = EventList.Where(e => e.WhatMashov == details.IsMashov).ToArray();
for (var i = 0; i < del.Length; i++)
{
EventList.Remove(del[i]);
}
details.SeparatorColor.Value = mainColor;
}
else
{
var add = Events?.Where(e => e.Day == details.Day && e.WhatMashov == details.IsMashov).ToArray();
details.SeparatorColor.Value = add.Length == 0? mainColor : Color.LightGray;
var after = details;
for (var i = 0; i < add.Length; i++)
{
add[i].SeparatorColor.Value = i == add.Length - 1 ? mainColor : Color.LightGray;
add[i].GridPadding = new Thickness(10, 10, 20, 10);
EventList.Insert(EventList.IndexOf(after) + 1, add[i]);
after = add[i];
}
}
EventList.Last().SeparatorColor.Value = Color.Transparent;
details.IsOpened = !details.IsOpened;
});
EventCommand = new Command<EventDetails>(async details =>
{
await NavigationService.Navigate<EventInfoViewModel>(model =>
{
model.Participants.AddRange(Participants?.Where(e => e.EventId == details.EventId));
model.Date.Value = SelectedDate;
model.EventDetails.Value = details;
model.Phone = Phone;
model.IsVisibleDescription.Value = !string.IsNullOrEmpty(details.Description);
model.IsVisibleLecturers.Value = model.Participants.Count > 0;
model.Conferance = Conferance;
model.AllEvents = Events;
model.Name = Name;
model.SelectedEventDetails = details;
model.QrDetails = QrDetails;
});
});
QrCommand = new Command<EventDetails>(details =>
{
if (details.QrState == QrState.Normal)
NavigationService.Navigate<QrPickerViewModel>(NavigationType.Popup, m => {
m.EventDetails = Events;
m.EventId = details.EventId;
m.QrDetails = QrDetails;
m.Phone = Phone;
m.Name = Name;
m.ConfId = Conferance.Id;
});
});
ViewImageCommand = new Command<CPhoto>(p =>
{
var s = p?.Path?.Trim();
var photos = CPhotos.Select(e => new MyPhoto {
URL = e?.Path?.Trim(),
Title = string.Empty,
Link = e?.SponsorLink?.Trim()
}).ToList();
if (Device.RuntimePlatform == Device.iOS)
photos.Reverse();
var pos = photos?.FindIndex(e => e.URL == s) ?? 0;
var config = new PhotoConfig {
Photos = photos,
StartIndex = pos,
ActionButtonPressed = async (index) => {
var action = await AlertCenter.ActionSheet(Device.RuntimePlatform == Device.Android ? Localization.SelectAction : null, Localization.Cancel, null, Localization.SponsorLink);
if (action == Localization.SponsorLink) {
if (string.IsNullOrEmpty(photos[index]?.Link)) {
AlertCenter.Error(Localization.NoLink);
}
else {
Device.OpenUri(new Uri(photos[index].Link, UriKind.Absolute));
}
}
}
};
config.Show();
});
PhotoCommand = new Command(async () =>
{
await LoadingPopupService.Show();
var photos = await SimpleServerRequest.Request<CPhoto[]>(new Uri("http://app.masham.org.il/insertToConfearnce2.php?Action=getAllEvents&TableName=I_" + Conferance.Id));
await LoadingPopupService.Close();
if (photos.Item1)
await NavigationService.Navigate<PhotoGalleryViewModel>(m =>
{
m.Photos.Value = photos.Item2.Where(e => e.Type == "גלריה").ToArray();
m.ConfId = Conferance.Id;
m.ApiKey = ApiKey;
});
else
AlertCenter.Error(Localization.ErrorLoading);
});
FeedbackCommand = new Command(async () =>
{
if (string.IsNullOrEmpty(Conferance?.SurvayLink))
{
AlertCenter.Error(Localization.NoLink);
return;
}
await LoadingPopupService.Show();
var res = await SimpleServerRequest.Request(new Uri($#"http://app.masham.org.il/insertToConfearnce2.php?Action=getServerDateAndtime&CID={Conferance.Id}"));
await LoadingPopupService.Close();
try
{
if (res.Success)
{
if (res.Result.ToLower() == "true")
Device.OpenUri(new Uri(Conferance?.SurvayLink, UriKind.Absolute));
else
AlertCenter.Error(Localization.NoMashovTime);
}
else
AlertCenter.Error(Localization.ErrorLoading);
}
catch
{
AlertCenter.Error(Localization.IncorrectLink);
}
});
LocationCommand = new Command(() =>
{
Device.OpenUri(new Uri("https://waze.com/ul?q=" + Conferance?.NameOfLocation));
});
ContactsCommand = new Command(async () =>
{
await NavigationService.Navigate<ContactsViewModel>(m =>
{
m.Phone.Value = Conferance?.Phone;
m.Location.Value = Conferance?.NameOfLocation;
m.Email.Value = Conferance?.Email;
});
});
MessagesCommand = new Command(async () =>
{
await LoadingPopupService.Show();
var messages = await SimpleServerRequest.Request<CMessage[]>(new Uri(
"http://app.masham.org.il/insertToConfearnce2.php?Action=getAllEvents&TableName=" +
"Messages_" + Conferance.Id));
await LoadingPopupService.Close();
if (messages.Item1)
{
DependencyService.Get<ILocalSettings>().PushCounter = 0;
await NavigationService.Navigate<MessagesViewModel>(m =>
{
m.Messages.AddRange(messages.Item2 ?? new CMessage[0]);
m.ConfId = Conferance.Id.ToString();
});
}
else
AlertCenter.Error(Localization.ErrorLoading);
});
FileCommand = new Command(() => {
if (string.IsNullOrEmpty(FileLink)) {
AlertCenter.Error(Localization.NoLink);
return;
}
Device.OpenUri(new Uri(FileLink, UriKind.Absolute));
});
}
public async void Resumed() {
{
if (_nowAsking)
return;
_nowAsking = true;
if (NavigationService.CurrentModalPage == null && NavigationService.CurrentPage.GetType() == typeof(DashboardPage) && !LoadingPopupService.IsLoading) {
IsBusy.Value = true;
await LoadingPopupService.Show();
var users = await SimpleServerRequest.Request<UserAndConferance[]>(new Uri($"http://app.masham.org.il/apimasham.php?Action=getUser&idUsername={Phone}&realId={RealId}"));
if (users.Item1) {
var user = users.Item2.FirstOrDefault();
ApiKey = user?.ApiKey;
var conf = users.Item2.Select(e => e.Conferance).FirstOrDefault(e => e != null && e.Id == Conferance.Id);
if (conf == null) {
_nowAsking = false;
IsBusy.Value = false;
Settings.Authed = false;
Settings.SavedPhone = "";
Settings.SavedId = "";
await LoadingPopupService.Close();
await AlertCenter.ErrorAsync(Localization.ConfNotFound);
await NavigationService.Navigate<LoginViewModel>();
NavigationService.ClearNavigationStack();
return;
}
var eventContainer = await SimpleServerRequest.Request<EventContainer>(new Uri($"http://app.masham.org.il/apimasham.php?Action=getEvents&confId={Conferance.Id}&phone={Phone}"));
if (eventContainer.Item1 && eventContainer.Item2 != null) {
var dates = eventContainer.Item2.EventDetails
?.Select(e => new {
e.Day,
e.HebrewDay
})
.Distinct()
.Select(e => new ThreeDatesItem {
Date = e.Day,
HebrewDate = e.HebrewDay
})
.OrderByDescending(e => e.Date)
.ToArray();
Events = eventContainer.Item2.EventDetails ?? new EventDetails[0];
QrDetails = eventContainer.Item2.QrDetails ?? new QrDetails[0];
QrStateHelper.SetQrStatesForAll(Events, QrDetails, eventContainer.Item2.QrAnswers);
if (conf.Type == "קורס" && dates != null) {
var p = 1;
for (var i = dates.Length - 1; i >= 0; i--) {
dates[i].HebrewDate = "מפגש " + p++;
}
}
var isEqualDates = Dates != null && Dates.Length == dates?.Length && conf.Type == Conferance.Type;
if (isEqualDates)
for (var i = 0; i < dates.Length; i++) {
isEqualDates = dates[i].Date == Dates[i].Date;
if (!isEqualDates)
break;
}
if (!isEqualDates)
Dates = dates;
var photos = eventContainer.Item2.Photos?.Where(e => e.Type == "קרוסלה").ToArray();
var isEqualPhotos = CPhotos != null && CPhotos.Length == photos?.Length;
if (isEqualPhotos)
for (var i = 0; i < photos.Length; i++) {
isEqualPhotos = photos[i].Path == CPhotos[i].Path;
if (!isEqualPhotos)
break;
}
else
CPhotos = photos;
Conferance = conf;
FileLink = eventContainer.Item2.Photos?.FirstOrDefault(e => e.Type == "קובץ")?.Path;
OnPropertyChanged(nameof(Conferance));
PrepareDatesAndPhotos(!isEqualDates, !isEqualPhotos);
if (Events.Length > 0) {
EventsState.Value = BasePageState.Normal;
}
else {
EventList.Clear();
EventsState.Value = BasePageState.NoData;
}
_nowAsking = false;
IsBusy.Value = false;
await LoadingPopupService.Close();
return;
}
}
IsBusy.Value = false;
await LoadingPopupService.Close();
await AlertCenter.ErrorAsync(Localization.ErrorLoading);
}
_nowAsking = false;
}
}
public override async void FirstAppearing()
{
base.FirstAppearing();
NavigationService.ClearNavigationStack();
await Task.Delay(300);
Device.BeginInvokeOnMainThread(() => {
PrepareDatesAndPhotos();
});
}
void PrepareDatesAndPhotos(bool updDates = true, bool updPhotos = true) {
if (updPhotos)
MessagingCenter.Send(App.Current, "DashboardFillPhotos", CPhotos);
PhotosVisible.Value = CPhotos?.Any() ?? false;
if (Dates?.Any() ?? false) {
if (updDates) {
var today = Dates.FirstOrDefault(e => e.Date == DateTime.Today);
if (today != null) {
today.IsSelected = true;
SelectedDate = today;
}
else {
var date = Dates[Dates.Length - 1];
date.IsSelected = true;
SelectedDate = date;
}
MessagingCenter.Send(App.Current, "DashboardFillDates");
}
else {
SelectedDate = SelectedDate;
}
}
}
private EventDetails[] GetEvents(DateTime date)
{
var items = Events?.Where(e => e.Day == date && e.WhatMashov == "").OrderBy(e => e.StartTime).ToArray();
var mainColor = (Color)Application.Current.Resources["SelectionColor"];
if (items?.Length > 0)
{
for (var i = 0; i < items.Length; i++)
{
items[i].IsOpened = false;
if (string.IsNullOrEmpty(items[i].IsMashov) && string.IsNullOrEmpty(items[i].WhatMashov))
{
items[i].SeparatorColor.Value = mainColor;
items[i].GridPadding = new Thickness(10, 10, 10, 10);
}
else
{
items[i].GridPadding = new Thickness(10, 10, 20, 10);
if (i != items.Length - 1)
{
if (!string.IsNullOrEmpty(items[i + 1].IsMashov) ||
!string.IsNullOrEmpty(items[i + 1].WhatMashov))
{
items[i].SeparatorColor.Value = Color.LightGray;
}
else
{
items[i].SeparatorColor.Value = mainColor;
}
}
}
}
items.Last().SeparatorColor.Value = Color.Transparent;
}
return items;
}
}
Good day
I am currently facing a weird problem with my insert command on my client side I think. I can create new entries in my other models(Tables) easily but in my person model I keep getting a bad request message each time I click create account.
Backend Model:
public class Person : EntityData
{
[StringLength(20)]
public string Name { get; set; }
[StringLength(20)]
public string Surname { get; set; }
[StringLength(150)]
public string Email { get; set; }
[StringLength(15)]
public string Mobile { get; set; }
[StringLength(15)]
public string Work { get; set; }
[StringLength(14)]
public string Password { get; set; }
[StringLength(80)]
public string Company { get; set; }
public virtual City City { get; set; }
}
Client Side Controller:
namespace azuremobile
{
public partial class PersonManager
{
static PersonManager defaultInstance = new PersonManager();
MobileServiceClient client;//Initialize Mobile SDK
IMobileServiceTable<Person> accountTable;
private PersonManager()
{
var handler = new AuthHandler();
//Create our client and pass in Authentication handler
this.client = new MobileServiceClient(
Constants.ApplicationURL, handler);
this.accountTable = client.GetTable<Person>();
}
public static PersonManager DefaultManager
{
get
{
return defaultInstance;
}
private set
{
defaultInstance = value;
}
}
public MobileServiceClient CurrentClient//Provides basic access to azure mobile services
{
get { return client; }
}
public bool IsOfflineEnabled
{
get { return accountTable is Microsoft.WindowsAzure.MobileServices.Sync.IMobileServiceSyncTable<Person>; }
}
public async Task<Person> GetTodoItemsAsync(Expression<Func<Person, bool>> linq)
//public async Task<List<Person>> GetTodoItemsAsync(bool syncItems = false)
{
try
{
// return new List<Person>(await accountTable.ReadAsync());
//List<Person> newUser = await accountTable.Where(linq).Take(1).ToListAsync();
IEnumerable<Person> items = await accountTable
.Where(c => c.Name != null)
.Take(1)
.ToListAsync();
//return newUser.First();
// return await accountTable;
// .Where(c => c.Name != null)
// .Take(1)
// .ToListAsync();
}
catch (MobileServiceInvalidOperationException msioe)
{
Debug.WriteLine(#"Invalid sync operation: {0}", msioe.Message);
}
catch (Exception e)
{
Debug.WriteLine(#"Sync error: {0}", e.Message);
}
return null;
}
public async Task SaveTaskAsync(Person item)
{
// if (item.Id != null)
// await accountTable.InsertAsync(item);
// else
await accountTable.UpdateAsync(item);
}
public async Task CreateTaskAsync(Person item)
{
try
{
await accountTable.InsertAsync(item);
}
catch (MobileServiceInvalidOperationException msioe)
{
Debug.WriteLine(#"INVALID {0}", msioe.Message);
}
catch (Exception e)
{
Debug.WriteLine(#"ERROR {0}", e.Message);
}
}
}
}
Client Side Signup Screen:
public partial class SignupScreen : ContentPage
{
PersonManager manager;
public SignupScreen()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
manager = PersonManager.DefaultManager;
LoginClicked.Clicked += async (object sender, EventArgs e) =>
{
var main = new LoginScreen();
Application.Current.MainPage = main;
Navigation.RemovePage(this);
};
}
async Task CreatedNewUser(Person items)
{
try
{
await manager.CreateTaskAsync(items);
}
catch (MobileServiceInvalidOperationException e)
{
await DisplayAlert("Info", e.Message, "Ok");
}
}
public async void OnSignUp(object sender, EventArgs e)
{
string name = this.nameEntry.Text.Trim();
string surname = this.surnameEntry.Text.Trim();
string email = this.emailEntry.Text.Trim();
string company = this.companyEntry.Text.Trim();
string work = this.workEntry.Text.Trim();
string mobile = this.mobileEntry.Text.Trim();
string password = this.passwordEntry.Text.Trim();
if (string.IsNullOrEmpty(name))
{
await DisplayAlert("Info", "Please fill in your name.", "Ok");
this.nameEntry.PlaceholderColor = this.nameEntry.TextColor = Color.FromHex("#00FF00");
nameEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
if (string.IsNullOrEmpty(surname))
{
await DisplayAlert("Info", "Please fill in your surname.", "Ok");
this.surnameEntry.PlaceholderColor = this.surnameEntry.TextColor = Color.FromHex("#00FF00");
surnameEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
if (string.IsNullOrEmpty(email))
{
await DisplayAlert("Info", "Please fill in your email.", "Ok");
this.emailEntry.PlaceholderColor = this.emailEntry.TextColor = Color.FromHex("#00FF00");
emailEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
if (string.IsNullOrEmpty(company))
{
await DisplayAlert("Info", "Please fill in your company name.", "Ok");
this.companyEntry.PlaceholderColor = this.companyEntry.TextColor = Color.FromHex("#00FF00");
companyEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
if (string.IsNullOrEmpty(mobile))
{
await DisplayAlert("Info", "Please fill in your cellphone number.", "Ok");
this.mobileEntry.PlaceholderColor = this.mobileEntry.TextColor = Color.FromHex("#00FF00");
mobileEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
if (string.IsNullOrEmpty(work))
{
await DisplayAlert("Info", "Please fill in your office number.", "Ok");
this.workEntry.PlaceholderColor = this.workEntry.TextColor = Color.FromHex("#00FF00");
workEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
if (string.IsNullOrEmpty(password))
{
await DisplayAlert("Info", "Please fill in your password.", "Ok");
this.passwordEntry.PlaceholderColor = this.passwordEntry.TextColor = Color.FromHex("#00FF00");
passwordEntry.Focus();
signUpButton.IsEnabled = true;
return;
}
try
{
activityIndicator.IsRunning = true;
validationLabel.IsVisible = true;
signUpButton.IsEnabled = false;
if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
{
var OnAdd = new Person
{
Name = name,
Surname = surname,
Email = email,
Mobile = mobile,
Work = work,
Company = company,
Password = password
};
await CreatedNewUser(OnAdd);
await Navigation.PushAsync(new LoginScreen());
}
else
{
await DisplayAlert("Warning", "Could not create user account.", "Ok");
}
}
catch (Exception)
{
await DisplayAlert("Warning", "Could not create user account, problem with internet connection or server.", "Ok");
activityIndicator.IsRunning = false;
validationLabel.IsVisible = false;
signUpButton.IsEnabled = true;
}
}
}
}
I have implemented Complex custom Foolproof validation in my application from this link but sadly its not working.My requirement is simple,I have a input file for uploading an image and there should be a validation if the user chooses to upload file other than specified below
".jpg",".png",".gif",".jpeg"
Code is
[Required(ErrorMessage = "Please upload Photo", AllowEmptyStrings = false)]
[IsValidPhoto(ErrorMessage="Please select files of type .jpg,.png,.gif,.jpeg")]
public HttpPostedFileBase PhotoUrl { get; set; }
public class IsValidPhotoAttribute : ModelAwareValidationAttribute
{
//this is needed to register this attribute with foolproof's validator adapter
static IsValidPhotoAttribute() { Register.Attribute(typeof(IsValidPhotoAttribute)); }
public override bool IsValid(object value, object container)
{
if (value != null)
{
string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".jpeg" };
var file = value as HttpPostedFileBase;
if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
{
return false;
}
}
return true;
}
}
CSHTML is
#Html.TextBoxFor(m => m.PhotoUrl, new { #class = "form-control imgUpload",
#placeholder = "Please upload Photo", #id = "txtPhoto", #type = "file" })
#Html.ValidationMessageFor(m => m.PhotoUrl)
You will not be able to get client side validation unless you also create a script to add the rules. It is not necessary to use foolproof and the following method and scripts will give you both server and client side validation
public class FileAttachmentAttribute : ValidationAttribute, IClientValidatable
{
private List<string> _Extensions { get; set; }
private const string _DefaultErrorMessage = "Only file types with the following extensions are allowed: {0}";
public FileAttachmentAttribute(string fileExtensions)
{
_Extensions = fileExtensions.Split('|').ToList();
ErrorMessage = _DefaultErrorMessage;
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
HttpPostedFileBase file = value as HttpPostedFileBase;
if (file != null)
{
var isValid = _Extensions.Any(e => file.FileName.EndsWith(e));
if (!isValid)
{
return new ValidationResult(string.Format(ErrorMessageString, string.Join(", ", _Extensions)));
}
}
return ValidationResult.Success;
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{
ValidationType = "fileattachment",
ErrorMessage = string.Format(ErrorMessageString, string.Join(", ", _Extensions))
};
rule.ValidationParameters.Add("extensions", string.Join(",", _Extensions));
yield return rule;
}
}
Scripts
$.validator.unobtrusive.adapters.add('fileattachment', ['extensions'], function (options) {
var params = { fileattachment: options.params.extensions.split(',') };
options.rules['fileattachment'] = params;
if (options.message) {
options.messages['fileattachment'] = options.message;
}
});
$.validator.addMethod("fileattachment", function (value, element, param) {
var extension = getExtension(value);
return $.inArray(extension, param.fileextensions) !== -1;
});
function getExtension(fileName) {
var extension = (/[.]/.exec(fileName)) ? /[^.]+$/.exec(fileName) : undefined;
if (extension != undefined) {
return extension[0];
}
return extension;
};
and then use it as
[FileAttachment("jpg|gif|png|jpeg")]
public HttpPostedFileBase PhotoUrl { get; set; }
In our application we use MvcContrib for generating links with the exception of cross area links where Contrib seems to be not working properly (or we are doing something wrong). In services we have a function that generates a List< ZakladkaModel > which contains url and other properties used in generating tabstrib via custom html helper. That function takes as an argument an id of database object and UrlHelper to help in link creating.
m_service.GenerowanieZakladkiDlaKontrolera_ARCH_Akt(idAktu, new UrlHelper(this.ControllerContext.RequestContext));
Then in the GenerowanieZakladkiDlaKontrolera_ARCH_Akt we have something like this:
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "Akt", Url = "" });
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "Wzmianki", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.ARCH_WzmiankiController>(c => c.Index(idAktu)) });
if (tekstJednolity.StanTekstuJednolitego == "RB" || tekstJednolity.StanTekstuJednolitego == "SW")
{
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "t.j. aktu", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.ARCH_TekstJednolityController>(c => c.Edytuj(tekstJednolity.Id)) });
}
else
{
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "t.j. aktu", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.ARCH_TekstJednolityController>(c => c.Raport(tekstJednolity.Id)) });
}
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "Przypisek 1", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.Przypisek1Controller>(c => c.Index(idAktu)) });
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "Przypisek 2", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.Przypisek2Controller>(c => c.Index(idAktu)) });
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "Przypisek 3", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.Przypisek3Controller>(c => c.Edytuj(idAktu)) });
model.Add(new ZakladkaModel { Aktywnosc = true, NazwaZakladki = "Przypisek 4", Url = url.Action<Usc.Presentation.Areas.FU_RAU.Controllers.ARCH.Przypisek4Controller>(c => c.Edytuj(idAktu)) });
Now the problem is that on some co-workers computers it generates links to actions properly and on some it looks like it takes a ranedom area from our app and tries to make an invalid link. We could use a simple url.Action("action","controler") which works fine on all but we would prefer MvcContrib :). Does anyone have any idea why this occurs? Or can share an alternative?
It seems that LinkBuilder which is used under doesn't use GetVirtualPatchForArea at all which as I read is MVC bug. So i decided to make my own HtmlHelper which uses that method:
public static string ActionArea<TController>(this HtmlHelper urlHelper, Expression<Action<TController>> expression) where TController : Controller
{
RouteValueDictionary routeValues = GetRouteValuesFromExpression(expression);
VirtualPathData vpd = new UrlHelper(urlHelper.ViewContext.RequestContext).RouteCollection.GetVirtualPathForArea(urlHelper.ViewContext.RequestContext, routeValues);
return (vpd == null) ? null : vpd.VirtualPath;
}
public static string ActionArea<TController>(this UrlHelper urlHelper, Expression<Action<TController>> expression) where TController : Controller
{
RouteValueDictionary routeValues = GetRouteValuesFromExpression(expression);
VirtualPathData vpd = urlHelper.RouteCollection.GetVirtualPathForArea(urlHelper.RequestContext, routeValues);
return (vpd == null) ? null : vpd.VirtualPath;
}
public static RouteValueDictionary GetRouteValuesFromExpression<TController>(Expression<Action<TController>> action) where TController : Controller
{
if (action == null)
{
throw new ArgumentNullException("action");
}
MethodCallExpression call = action.Body as MethodCallExpression;
if (call == null)
{
throw new ArgumentException("Akcja nie może być pusta.", "action");
}
string controllerName = typeof(TController).Name;
if (!controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("Docelowa klasa nie jest kontrolerem.(Nie kończy się na 'Controller')", "action");
}
controllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length);
if (controllerName.Length == 0)
{
throw new ArgumentException("Nie można przejść do kontrolera.", "action");
}
// TODO: How do we know that this method is even web callable?
// For now, we just let the call itself throw an exception.
string actionName = GetTargetActionName(call.Method);
var rvd = new RouteValueDictionary();
rvd.Add("Controller", controllerName);
rvd.Add("Action", actionName);
var namespaceNazwa = typeof(TController).Namespace;
if(namespaceNazwa.Contains("Areas."))
{
int index = namespaceNazwa.IndexOf('.',namespaceNazwa.IndexOf("Areas."));
string nazwaArea = namespaceNazwa.Substring(namespaceNazwa.IndexOf("Areas.") + 6, index - namespaceNazwa.IndexOf("Areas.") + 1);
if (!String.IsNullOrEmpty(nazwaArea))
{
rvd.Add("Area", nazwaArea);
}
}
//var typ = typeof(TController).GetCustomAttributes(typeof(ActionLinkAreaAttribute), true /* inherit */).FirstOrDefault();
/*ActionLinkAreaAttribute areaAttr = typ as ActionLinkAreaAttribute;
if (areaAttr != null)
{
string areaName = areaAttr.Area;
rvd.Add("Area", areaName);
}*/
AddParameterValuesFromExpressionToDictionary(rvd, call);
return rvd;
}
private static string GetTargetActionName(MethodInfo methodInfo)
{
string methodName = methodInfo.Name;
// do we know this not to be an action?
if (methodInfo.IsDefined(typeof(NonActionAttribute), true /* inherit */))
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
"Nie można wywoływać metod innych niż akcje.", methodName));
}
// has this been renamed?
ActionNameAttribute nameAttr = methodInfo.GetCustomAttributes(typeof(ActionNameAttribute), true /* inherit */).OfType<ActionNameAttribute>().FirstOrDefault();
if (nameAttr != null)
{
return nameAttr.Name;
}
// targeting an async action?
if (methodInfo.DeclaringType.IsSubclassOf(typeof(AsyncController)))
{
if (methodName.EndsWith("Async", StringComparison.OrdinalIgnoreCase))
{
return methodName.Substring(0, methodName.Length - "Async".Length);
}
if (methodName.EndsWith("Completed", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
"Nie można wywoływać kompletnych metod.", methodName));
}
}
// fallback
return methodName;
}
static void AddParameterValuesFromExpressionToDictionary(RouteValueDictionary rvd, MethodCallExpression call)
{
ParameterInfo[] parameters = call.Method.GetParameters();
if (parameters.Length > 0)
{
for (int i = 0; i < parameters.Length; i++)
{
Expression arg = call.Arguments[i];
object value = null;
ConstantExpression ce = arg as ConstantExpression;
if (ce != null)
{
// If argument is a constant expression, just get the value
value = ce.Value;
}
else
{
value = CachedExpressionCompiler.Evaluate(arg);
}
rvd.Add(parameters[i].Name, value);
}
}
}
Hope this helps people with similiar problems. Some of the code above i got from mvc2-rtm-sources modified to my needs http://aspnet.codeplex.com/releases/view/41742
I am using Hidden fields to maintain the state of my checkboxes between page requests except it doesn't work. So when I click on my webgrid to go to the next 15 records it forgets which checkboxes are checked.
Index view
#model IEnumerable<UserManager.Models.vw_UserManager_Model>
#{
ViewBag.Title = "User Manager Dashboard";
}
#Html.ActionLink("Create New User", "CreateUser")
#using (#Html.BeginForm())
{
<div class="webgrid-filter">
#{Html.RenderAction("_WebGridFilter", "UserManager");}
</div>
<div id="webgrid-wrapper">
#Html.Partial("~/Views/Partial/_WebGridUserManager.cshtml", Model)
</div>
<br />
}
<script type="text/javascript">
$(document).ready(function () {
// Disable checkboxs where a user is not active.
$(".webgrid-wrapper input:not(:checked)").attr("disabled", "disabled");
// Style tables.
function jQueryUIStyling() {
$('input:button, input:submit').button();
$('.webgrid-wrapper').addClass('ui-grid ui-widget ui-widget-content ui-corner-all');
$('.webgrid-title').addClass('ui-grid-header ui-widget-header ui-corner-top');
jQueryTableStyling();
} // end of jQueryUIStyling
function jQueryTableStyling() {
$('.webgrid').addClass('ui-grid-content ui-widget-content');
$('.webgrid-header').addClass('ui-state-default');
$('.webgrid-footer').addClass('ui-grid-footer ui-widget-header ui-corner-bottom ui-helper-clearfix');
} // end of jQueryTableStyling
});
</script>
<script type="text/javascript">
function filterGrid() {
var filters = getFilterVals();
$.ajax({
url: '#Url.Action("Index", "UserManager")',
type: "POST",
async: true,
dataType: "html",
data: "alfConnect=" + filters.alfConnect + "&" + "alfIntelligence=" + filters.alfIntelligence + "&" + "brad=" + filters.brad,
success: function (data) {
$('#webgrid-wrapper').empty().html(data);
// $('#webgrid-wrapper').html(data);
}
});
}
function getFilterVals() {
filters = new Object();
if ($('.webgrid-filter #chkFilterAlfIntell').is(':checked')) {
filters.alfIntelligence = 1;
}
else {
filters.alfIntelligence = 0;
}
if ($('.webgrid-filter #chkFilterAlfConn').is(':checked')) {
filters.alfConnect = 1;
}
else {
filters.alfConnect = 0;
}
if ($('.webgrid-filter #chkFilterBrad').is(':checked')) {
filters.brad = 1;
}
else {
filters.brad = 0;
}
return filters;
}
function logUserOff(url) {
var answer = confirm('Are you sure you want to save this data?')
if (answer) {
// alert(url + ": " + value);
$.ajax({
url: url,
type: "POST"
// data: value
}).done(function () {
$(this).addClass("done");
});
return true;
}
else {
return false;
}
};
</script>
Partial view with hidden fields
#model UserManager.Models.webgrid_validation
<b>#Html.Label("Select a filter: ")</b>
<br />
#Html.Label("Toggle ALF Intelligence users:")
#Html.CheckBoxFor(model => model.chkBoxAlfIntelligence, new
{
id = "chkFilterAlfIntell",
onclick = "filterGrid()",
#checked = "checked"
})
#Html.Hidden("hdnAlfIntelligence", Model.chkBoxAlfIntelligence)
#Html.Label("Toggle ALF Connect users:")
#Html.CheckBoxFor(model => model.chkBoxAlfConnect, new
{
id = "chkFilterAlfConn",
onclick = "filterGrid()",
#checked = "checked"
})
#Html.Hidden("hdnAlfConnect", Model.chkBoxAlfConnect)
#Html.Label("Toggle BRAD users:")
#Html.CheckBoxFor(model => model.chkBoxBrad, new
{
id = "chkFilterBrad",
onclick = "filterGrid()",
#checked = "checked"
})
#Html.Hidden("hdnBrad", Model.chkBoxBrad)
Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UserManager.Models;
namespace UserManager.Controllers
{
public class UserManagerController : Controller
{
//
// GET: /UserManager/
public ActionResult Index()
{
try
{
var model = new UserManagerTestEntities().vw_UserManager_Model;
return View(model.ToList());
}
catch (Exception ex)
{
return View(ViewBag);
}
}
[HttpPost]
public ActionResult Index(int alfConnect, int alfIntelligence, int brad)
{
List<UserManager.Models.vw_UserManager_Model> modelList = DAL.getGrid(alfConnect, alfIntelligence, brad);
switch (alfConnect)
{
case 1:
ViewData["chkBoxAlfConnect"] = 1;
break;
case 0:
ViewData["chkBoxAlfConnect"] = 0;
break;
}
switch (alfIntelligence)
{
case 1:
ViewData["chkBoxAlfIntelligence"] = 1;
break;
case 0:
ViewData["chkBoxAlfIntelligence"] = 0;
break;
}
switch (brad)
{
case 1:
ViewData["chkBoxBrad"] = 1;
break;
case 0:
ViewData["chkBoxBrad"] = 0;
break;
}
return PartialView("~/Views/Partial/_WebGridUserManager.cshtml", modelList);
}
[ChildActionOnly]
public ActionResult _WebGridFilter ()
{
UserManager.Models.webgrid_validation model = new webgrid_validation();
return PartialView("~/Views/Partial/_WebGridFilter.cshtml", model);
}
//public ActionResult _WebGridFilter(int alfConnect, int alfIntelligence, int brad)
//{
// UserManager.Models.webgrid_validation model = new webgrid_validation();
//switch (alfConnect)
//{
// case 1:
// model.chkBoxAlfConnect = true;
// break;
// case 0:
// model.chkBoxAlfConnect = false;
// break;
//}
//switch (alfIntelligence)
//{
// case 1:
// model.chkBoxAlfIntelligence = true;
// break;
// case 0:
// model.chkBoxAlfIntelligence = false;
// break;
//}
//switch (brad)
//{
// case 1:
// model.chkBoxBrad = true;
// break;
// case 0:
// model.chkBoxBrad = false;
// break;
//}
// return PartialView("~/Views/Partial/_WebGridFilter.cshtml", model);
//}
#region ajaxMethods
public ActionResult LookUpGroupName(string q, int limit)
{
try
{
//TODO: Map list to autocomplete textbox control
DAL d = new DAL();
List<string> groups = d.groups();
var GroupValue = groups
.Where(x => x.Contains(q))
.OrderBy(x => x)
.Take(limit)
.Select(r => new { group = r });
// Return the result set as JSON
return Json(GroupValue, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return View(ex.ToString());
}
}
public ActionResult LogUserOff(string userid)
{
try
{
//TODO: Map list to autocomplete textbox control
return View();
}
catch (Exception ex)
{
return View(ex.ToString());
}
}
//[HttpPost]
//public ActionResult FilterGrid(int alfConnect, int alfIntelligence, int brad)
//{
// List<UserManager.Models.vw_UserManager_Model> modelList = DAL.getGrid(alfConnect, alfIntelligence, brad);
// return PartialView("_WebGridUserManager", modelList);
//}
#endregion
#region crud
public ActionResult CreateUser()
{
//var data = new UserManager.Models.UserManagerTestEntities();
ViewBag.Message = "Create New User";
var model = new vw_UserManager_Model();
return View(model);
}
[HttpPost]
public ActionResult CreateUser (vw_UserManager_Model model)
{
int outcome = 0;
if (ModelState.IsValid)
{
//var data = new UserManager.Models.UserManagerTestEntities();
// Pass model to Data Layer
outcome = UserManager.DAL.CreateUser(model, outcome);
//data.SaveChanges();
}
if (outcome > 0) // Success
{
return RedirectToAction("showSuccess", model);
}
else // Failure
{
return RedirectToAction("showError", new { ErrorMessage = "Error" });
}
}
public ActionResult EditUser(Guid userid, string salutation, string firstname, string lastname, string password, Nullable<bool> isactive, Nullable<int> maxconcurrentusers, string email, string module, string group)
{
vw_UserManager_Model editUser = new vw_UserManager_Model();
editUser.userid = userid;
editUser.salutation = salutation;
editUser.firstname = firstname;
editUser.lastname = lastname;
editUser.password = password;
editUser.isactive = isactive;
editUser.MaxConcurrentUsers = maxconcurrentusers;
editUser.email = email;
editUser.module_name = module;
editUser.group_name = group;
return View(editUser);
}
[HttpPost]
public ActionResult EditUser(vw_UserManager_Model editUser)
{
if (ModelState.IsValid)
{
UserManager.DAL.EditUser(editUser);
}
return View();
}
public ActionResult DeleteUser(Guid userid, string username, string salutation, string firstname, string lastname, string password, bool isactive, string email, string module, string group)
{
vw_UserManager_Model DeleteUser = new vw_UserManager_Model();
DeleteUser.userid = userid;
DeleteUser.UserName = username;
DeleteUser.salutation = salutation;
DeleteUser.firstname = firstname;
DeleteUser.lastname = lastname;
DeleteUser.password = password;
DeleteUser.isactive = isactive;
DeleteUser.email = email;
DeleteUser.module_name = module;
DeleteUser.group_name = group;
return View(DeleteUser);
}
[HttpPost]
public ActionResult DeleteUser(vw_UserManager_Model deleteUser)
{
if (ModelState.IsValid)
{
UserManager.DAL.DeleteUser(deleteUser);
return RedirectToAction("showSuccess", new { SuccessMessage = "Success" });
}
return View();
}
#endregion crud
#region successErrorHandling
public ActionResult showError(List<string> ErrorMessage)
{
ViewBag.ErrorMessage = ErrorMessage[0];
return View("ErrorMessageView");
}
public ActionResult showSuccess(vw_UserManager_Model model)
{
return View("SuccessMessageeView", model);
}
#endregion
}
}
My question is how to use hidden fields to maintain state of checkboxes between page request?
you could remove the form and send data to the controller as JSon values, and thus refresh only the part of the page that needs to be refreshed.
Regards