spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

how to collect the name and values stored in a model to a dictionary and finally merge these separate variables into one in c# mvc


Use of a dictionary seems unnecessary and I'm not sure how that would solve you problem. I suggest you create a class that contains the 3 properties you want to display in the view

public class PropertiesVM
{
    public string Name { get; set; }
    public object OldValue { get; set; }
    public object NewValue { get; set; }
}

and in the controller

public JsonResult GetProperties()
{
  UserModel old = //
  UserModel new = //
  List<PropertiesVM> model = new
List<PropertiesVM>();
  foreach (PropertyInfo propertyInfo in
typeof(UserModel).GetProperties())
  {
    PropertiesVM prop = new PropertiesVM();
    prop.Name = propertyInfo.Name;
    prop.OldValue = propertyInfo.GetValue(old,
null);
    prop.NewValue = propertyInfo.GetValue(new,
null);
    propertyNameList.Add(prop);
  }
  return Json(model,
JsonRequestBehavior.AllowGet);
}

and in the ajax success callback, something like

$.each(data, function(index, item) {
  var row = $('<tr></tr>');
 
row.append($('<td></td>').text(item.Name));
 
row.append($('<td></td>').text(item.OldValue));
 
row.append($('<td></td>').text(item.NewValue));
  $('table').append(row);
});

Categories : C#

Related to : how to collect the name and values stored in a model to a dictionary and finally merge these separate variables into one in c# mvc
how to collect the name and the value stored in a model to a list in c# mvc
Ok I think this might be what you are trying to do but it is hard to know without seeing your model and your expected output properly formatted. public List<string> GetPropertiesNameOfClass(UserModel olduser, UserModel newuser) { var propertyNameList = new List<string>(); var propertyOldValue = new List<object>(); var propertyNewValue = new List<object>();

Categories : C#
How to store and access values stored in a Session Object on separate form pages
Try to use keys to store values: request.session['fav_color'] = 'red' #Set the value fav_color = request.session.get('fav_color', 'red') #Read the value else read a default one From Django Doc: A wrapper around the JSON serializer from django.core.signing. Can only serialize basic data types. In addition, as JSON supports only string keys, note that using non-string keys in request.session won

Categories : Python
userHow to collect the values from html form for variable input values in google app script?
This code takes the value of an array, and creates an object: function getFormValue(formValue) { formValue = ["someInput1", "someInput2", "someInput3", "someInput4", "someInput5", "someInput6", "someInput7"]; Logger.log('formValue: ' + formValue); var myarr= {}; var count = formValue.length; Logger.log('count: ' + count); var user = {}; for(var g = 1; g<=count; g++ ) {

Categories : Javascript
Sorting a dictionary of dictionary using values in Python
If you want order you need an OrderedDict of OrderedDicts, by chance the outer dict is in sorted order but normal dicts have no order: from collections import OrderedDict d = { 1: {2: 30, 3: 40, 4: 20, 6: 10}, 2: {3: 30, 4: 60, 5: -60}, 3: {1: -20, 5: 60, 6: 100}, } keys = sorted(d.keys()) # sort outer dict keys o = OrderedDict() for k in keys: # loop over the sor

Categories : Python
how to merge separate date and time variable into one datetime format XSLT
Use the following XSLT: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://tst.co.za/sa/co/cib/servicesV1" exclude-result-prefixes="ns0"> <xsl:output indent="yes" method="xml" omit-xml-declaration="yes" /> <xsl:strip-space elements="*"/> <xsl:template match="/ns0:TransactionRequests/Cor

Categories : Xml
Recently Add
How to call a method in .cs file which was implemented in code behind?
How To Prevent $variables In Restangular Post Request
Windows Phone 8 VoIP SIP Provider
How do we set the AutoCAD layer viewport override values
Load Dependent DLL using reflection
The code is not showing any error but still not displaying data on the datagrid of webform.?
Make an Image that can be flipped over in Unity 4.6
Storing JSON REST response in object
which is more efficient in conditional looping?
WebBrowser control's shortcut keys are not working
C# SQL INSERT not appearing in database table "no errors or exceptions thrown"
c# winfrom treeview class binding
How to Convert string "00h:03m:30s:793ms" to TimeSpan in c#
Calling a parameterized Stored Procedure that returns a value in C#
How to use the SQL statement to transform the data from row record to column record
How to Instantiate Enemy Prefabs Without Knowing the Name
MVC JQuery unobtrusive validation
How to draw at top left of metaFile
How to make Aggregate Root method only accessible for a Domain Event and nothing else.
how to create a list of lists from one list using LINQ?
Ignore user roles in ASP .Net MVC 5 Identity
Xpath Web scrape
add property to interface
How can I make controls added to existing mark-up be automatically hooked up to the code behind?
Too much data in C# windows form combobox, taking 30 sec to show the windows form
Creating a scrolling grid of images using WPF and XAML
PHP equivalent to asp.net routing
LINQ aggregate query
Custom Control won't fill dock correctly
Get ASP.NET Identity Current User In View
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.