0%

How can read the posted grid data line by line?

You can create a Model for Stock and it can be bind to your view. Then you can pass list of stock objects to controller as below.

Stock Model

1
2
3
4
5
6
public class Stock
{
public int StockId { get; set; }
public int Amount { get; set; }
public decimal Price { get; set; }
}

View

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@model IEnumerable<Stock>
<form action="/Controler/ActionStockNew" method="post" id="form">
<table>
@for (int i = 0; i < Model.Count(); i++)
{<tr>
<td>
<input type="text" name="[@i].StockId" />
</td>
<td>
<input type="text" name="[@i].Amount" />
</td>
<td>
<input type="text" name="[@i].Price" />
</td>
</tr>
}
</table>
<input type="submit" value="Save" />
</form>

Controllers

1
2
3
4
5
6
7
8
9
10
11
12
13
public ActionResult ActionStockNew()
{
List<Stock> stockList = new List<Stock>();
// fill stock

return View(stockList);
}

[HttpPost]
public ActionResult ActionStockNew(ICollection<Stock> stockList)
{
// process
}

Here is a simplified example:

1
2
3
4
5
6
7
8
public static bool operator ==(ThreeDPoint a, ThreeDPoint b)
{
if (a == null)
{
//any code here never gets executed! We first die a slow painful death.
}
return a.Equals(b);
}

However, what happens when a ThreeDPoint object is null?

You can’t write:

1
2
3
4
5
ThreeDPoint  a;
if (a == null)
{
//fail!
}

Use object.ReferenceEquals(person1, null) instead of the == operator:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static bool operator ==(ThreeDPoint a, ThreeDPoint b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}

// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null))
{
return false;
}

// Return true if the fields match:
return a.x == b.x && a.y == b.y && a.z == b.z;
}

Razor views are dynamically compiled by the ASP.NET runtime. If you want your views to be built at compile-time you could add the following option to your .csproj file:

1
2
3
4
5
6
7
8
9
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>

...
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

You need to use the xsd.exe tool which gets installed with the Windows SDK into a directory something similar to:

1
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

And on 64bit computers:

1
C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\bin

On the first run, you use xsd.exe and you convert your sample XML into a XSD file (XML schema file):

1
xsd yourfile.xml

This gives you yourfile.xsd, which in a second step, you can convert again using xsd.exe into a C# class:

1
xsd yourfile.xsd /c

You can deserialize xml string to C# object:

1
2
3
StringReader sr = new StringReader(xmlStr);
XmlSerializer mySerializer = new XmlSerializer(typeof(YourObject));
YourObject obj = (YourObject)mySerializer.Deserialize(sr);

You can serialize object to simple xml string.
First, you must declare namespace in YourObject:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class YourObject
{
public YourObject()
{
this._namespaces = new XmlSerializerNamespaces(new XmlQualifiedName[] {
new XmlQualifiedName(string.Empty, "urn:Abracadabra") // Default Namespace
});
}

[XmlNamespaceDeclarations]
public XmlSerializerNamespaces Namespaces
{
get { return this._namespaces; }
}
private XmlSerializerNamespaces _namespaces;

...
}

Then you can start serialize obj to xml string:

1
2
3
4
5
6
MemoryStream ms = new MemoryStream();
XmlSerializer mySerializer = new XmlSerializer(typeof(YourObject));
mySerializer.Serialize(ms, obj, obj.Namespaces);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string strXml = sr.ReadToEnd();

The perform code is:

1
2
3
4
5
6
7
8
9
public static string GetGmtTimeString(this DateTime now)
{
double gmt = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
string gmtTime = string.Format("{0} GMT{1}{2}",
now.ToString("yyyy/MM/dd HH:mm:ss"),
(gmt >= 0) ? "+" : "",
gmt);
return gmtTime;
}

You can iterate and find the one you want:

1
2
3
4
5
6
var classList = $('#divId').attr('class').split(/\s+/);
$.each( classList, function(index, item){
if (item === 'someClass') {
//do something
}
});

Example 1:
Eg: For 7-zip, with 7-zip in the default Program Files folder.

.zip;.rar=C:\Program Files\7-Zip\7zFM.exe

Example 2:
Q-Dir is on the USB Stik and Notepad++ also.
The file extension “txt”, “cpp”, “pl”, “ini”, “php”, “cgi” to be with Notepad++ open.

.txt;.cpp;.pl;.ini;.php;.cgi=%drive%/npp/unicode/notepad++.exe

Or even for portable 7-Zip :

.zip;.rar;.7z;.tar;.iso;.lzh=%drive%/7-Zip/7zFM.exe

%drive% is a placeholder for the drive from which to Q-Dir is started.
In the case of: the Q-Dir path is “M:/Q-Dir/Q-Dir.exe” then would be %drive% a placeholder for “M:”.

This allows you to define yourself,
through the menu :
Extras >> … more options, then tab bar Association.

img

jQuery Multiple Attribute Selector

input name=value AND name2=value2

is perform following:

1
$['input[name="value"][name2="value2"]')

input name=value OR name2=value2

is perform following:

1
$['input[name="value"] , [name2="value2"]')