Adding multiple partial views and first one is missing form
I have the following:
_ImageGalleryPartial
@if (Model != null)
{
foreach (var item in Model)
{
@Html.Partial("_ImageItem", item);
}
}
_ImageItemPartial
@model WebsiteEngine.Models.PortfolioImage
@{
string url = VirtualPathUtility.ToAbsolute(String.Format("~/{0}",
Html.DisplayFor(m => m.FileName)));
}
@using (Html.BeginForm("DeleteImage", "Portfolio", FormMethod.Post, new {
@class = "deleteImageForm" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true);
@Html.HiddenFor(m => m.Name)
@Html.HiddenFor(m => m.FileName)
@Html.HiddenFor(m => m.Order)
@Html.HiddenFor(m => m.PortfolioID)
@Html.HiddenFor(m => m.PortfolioImageID)
<div class="span3">
<div class="item">
<a class="fancybox-button" data-rel="fancybox-button"
title="Photo" href="@url">
<div class="zoom">
<img src="@url" alt="Photo" />
<div class="zoom-icon"></div>
</div>
</a>
<div class="details">
<a href="#" class="icon deleteImage" data-form=""><i
class="icon-remove"></i></a>
</div>
</div>
</div>
}
When I inspect the page elements using Chrome dev tools, the first element
is missing the surrounding form. If I inspect the page source (using
right) click then the form is there. This lead me to believe some JS was
removing the form so I disabled JS but it was still missing.
If change _ImageGalleryPartial so it's like this (notice the addition of
an empty model):
@if (Model != null)
{
@Html.Partial("_ImageItem", new WebsiteEngine.Models.PortfolioImage());
foreach (var item in Model)
{
@Html.Partial("_ImageItem", item);
}
}
Then all the "correct" elements get a form but again, this first item
doesn't.
I'm still inclined to think this is a JS issue but I'm a little stumped as
disabling JS doesn't fix it. Is this some off behaviour with MVC?
Just to note, I have simplified my layout above, I do actually have one or
2 nested forms but assume that's Ok as everything else is Ok, it's just
this first partial that's broken.
Any ideas?
Wednesday, 2 October 2013
How to complexity
How to complexity
Please can any one provide with a better algorithm then trying all the
combinations for this problem.
Given an array A of N numbers,
find the number of distinct pairs (i, j) such that j >=i and A[i] = A[j].
First line of the input contains number of test cases T.
Each test case has two lines, first line is the number N,
followed by a line consisting of N integers which are the elements of
array A.
For each test case print the number of distinct pairs.
Constraints
1 <= T <= 10
1 <= N <= 10^6
-10^6 <= A[i] <= 10^6 for 0 <= i < N
I think that first sorting the array then finding frequency of every
distinct integer and then adding nC2 of all the frequencies plus adding
the length of the string at last. But unfortunately it gives wrong ans for
some cases which are not known help. here is the implementation.
code:
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long fun(long a) //to find the aC2 for given a
{
if(a==1) return 0;
return (a*(a-1))/2;
}
int main()
{long t,i,j,n,tmp=0;
long long count;
long ar[1000000];
cin>>t;
while(t--)
{cin>>n;
for(i=0;i<n;i++)
{
cin>>ar[i];
}
count =0;
sort(ar,ar+n);
for(i=0;i<n-1;i++)
{
if(ar[i]==ar[i+1]){tmp++;}
else {count +=fun(tmp+1);tmp=0; }
}
if(tmp!=0)
{count+=fun(tmp+1);}
cout<<count+n<<"\n";
}
return 0;
}
Please can any one provide with a better algorithm then trying all the
combinations for this problem.
Given an array A of N numbers,
find the number of distinct pairs (i, j) such that j >=i and A[i] = A[j].
First line of the input contains number of test cases T.
Each test case has two lines, first line is the number N,
followed by a line consisting of N integers which are the elements of
array A.
For each test case print the number of distinct pairs.
Constraints
1 <= T <= 10
1 <= N <= 10^6
-10^6 <= A[i] <= 10^6 for 0 <= i < N
I think that first sorting the array then finding frequency of every
distinct integer and then adding nC2 of all the frequencies plus adding
the length of the string at last. But unfortunately it gives wrong ans for
some cases which are not known help. here is the implementation.
code:
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long fun(long a) //to find the aC2 for given a
{
if(a==1) return 0;
return (a*(a-1))/2;
}
int main()
{long t,i,j,n,tmp=0;
long long count;
long ar[1000000];
cin>>t;
while(t--)
{cin>>n;
for(i=0;i<n;i++)
{
cin>>ar[i];
}
count =0;
sort(ar,ar+n);
for(i=0;i<n-1;i++)
{
if(ar[i]==ar[i+1]){tmp++;}
else {count +=fun(tmp+1);tmp=0; }
}
if(tmp!=0)
{count+=fun(tmp+1);}
cout<<count+n<<"\n";
}
return 0;
}
When i add image i cannot see the text box in jquery mobile?
When i add image i cannot see the text box in jquery mobile?
I am new to jquery mobile. when i add back ground image all the text box
are hidden . what can be done to add image and to see the text box .
Thanks in Advance
I am new to jquery mobile. when i add back ground image all the text box
are hidden . what can be done to add image and to see the text box .
Thanks in Advance
Tuesday, 1 October 2013
A bit of integration involving a continuous function
A bit of integration involving a continuous function
If $f$ is continuous on $[0,1]$ and if $\int_{0}^{1}f(x)x^ndx=0$ for
$n=0,1,2,3...$then $\int_{0}^{1}f^2(x)dx=0$.
This is how I proceeded. For $n=1$, $\int_{0}^{1}f(x)xdx=0$ . (Using by
parts) $\implies$ $x\int f(x)dx]_0^1-\int_{0}^{1}(\int f(x)dx)dx=0$. Let
$I(x)=\int f(x)dx$. Then $I(1)=\int_{0}^{1}I(x)dx$. For $n=2$ we have
$\int_{0}^{1}f(x)x^2dx= x\int xf(x)dx]_0^1-\int_{0}^{1}(\int xf(x)dx)dx=0$
In general for any $n$, $\int_{0}^{1}f(x)x^ndx=x\int
x^{n-1}f(x)dx]_0^1-\int_{0}^{1}(\int x^{n-1}f(x)dx)dx=0$.
Then I don't see how I can use this information to get the desired result.
If $f$ is continuous on $[0,1]$ and if $\int_{0}^{1}f(x)x^ndx=0$ for
$n=0,1,2,3...$then $\int_{0}^{1}f^2(x)dx=0$.
This is how I proceeded. For $n=1$, $\int_{0}^{1}f(x)xdx=0$ . (Using by
parts) $\implies$ $x\int f(x)dx]_0^1-\int_{0}^{1}(\int f(x)dx)dx=0$. Let
$I(x)=\int f(x)dx$. Then $I(1)=\int_{0}^{1}I(x)dx$. For $n=2$ we have
$\int_{0}^{1}f(x)x^2dx= x\int xf(x)dx]_0^1-\int_{0}^{1}(\int xf(x)dx)dx=0$
In general for any $n$, $\int_{0}^{1}f(x)x^ndx=x\int
x^{n-1}f(x)dx]_0^1-\int_{0}^{1}(\int x^{n-1}f(x)dx)dx=0$.
Then I don't see how I can use this information to get the desired result.
Function instance variables inside a class
Function instance variables inside a class
I'm trying to implement a so-called static variable in my method, similar
to the decorator method described in this Stackoverflow thread.
Specifically, I define a decorator function as follows:
def static_var(varName, value):
def decorate(function):
setattr(function,varName,value)
return function
return decorate
As the example shows, this can be used to attach a variable to the function:
@static_var('seed', 0)
def counter():
counter.seed +=1
return counter.seed
This method will return the number of times it has been called.
The issue i am having is that this does not work if I define the method
inside a class:
class Circle(object):
@static_var('seed',0)
def counter(self):
counter.seed +=1
return counter.seed
If I instantiate a Circle and run counter,
>>>> myCircle = Circle()
>>>> myCircle.counter()
I get the following error: NameError: global name 'counter' is not defined.
My response to this was that maybe I need to use self.counter, i.e.
class Circle(object):
@static_var('seed',0)
def counter(self):
self.counter.seed +=1
return self.counter.seed
However this produces the error, AttributeError: 'instancemethod' object
has no attribute 'seed'.
What is going on here?
I'm trying to implement a so-called static variable in my method, similar
to the decorator method described in this Stackoverflow thread.
Specifically, I define a decorator function as follows:
def static_var(varName, value):
def decorate(function):
setattr(function,varName,value)
return function
return decorate
As the example shows, this can be used to attach a variable to the function:
@static_var('seed', 0)
def counter():
counter.seed +=1
return counter.seed
This method will return the number of times it has been called.
The issue i am having is that this does not work if I define the method
inside a class:
class Circle(object):
@static_var('seed',0)
def counter(self):
counter.seed +=1
return counter.seed
If I instantiate a Circle and run counter,
>>>> myCircle = Circle()
>>>> myCircle.counter()
I get the following error: NameError: global name 'counter' is not defined.
My response to this was that maybe I need to use self.counter, i.e.
class Circle(object):
@static_var('seed',0)
def counter(self):
self.counter.seed +=1
return self.counter.seed
However this produces the error, AttributeError: 'instancemethod' object
has no attribute 'seed'.
What is going on here?
How safety is Ubuntu Tweak Janitor for system?
How safety is Ubuntu Tweak Janitor for system?
I had some trouble with Tweak Janitor.
I cleaned my system with all checkboxes that was available.
After cleaning when I restarted PC I caught to text terminal it's all, smt:
Ubuntu 12.04.3 LTS nazar-desctop tty1
nazar-dezsctop login: // I typed correct login + password
nazar-dezsctop password:
and after log in next info:
7 packages can be updated
7 updatees are security updates
I got out from this trouble by next steps:
Stop LightDM with sudo stop lightdm
Install GDM with sudo apt-get install gdm
Start GDM with sudo start gdm
Run sudo dpkg-reconfigure lightdm to set the default display manager for gdm
Restart computer and login.
I wondering to know about safety usage of Ubuntu Tweak Janitor.
Question:
For example what happen if I'll try to use it again in the future?
If I had use LightDM what would happen?
Why ubuntu didn't tall me about these updates after cleaning?
I had some trouble with Tweak Janitor.
I cleaned my system with all checkboxes that was available.
After cleaning when I restarted PC I caught to text terminal it's all, smt:
Ubuntu 12.04.3 LTS nazar-desctop tty1
nazar-dezsctop login: // I typed correct login + password
nazar-dezsctop password:
and after log in next info:
7 packages can be updated
7 updatees are security updates
I got out from this trouble by next steps:
Stop LightDM with sudo stop lightdm
Install GDM with sudo apt-get install gdm
Start GDM with sudo start gdm
Run sudo dpkg-reconfigure lightdm to set the default display manager for gdm
Restart computer and login.
I wondering to know about safety usage of Ubuntu Tweak Janitor.
Question:
For example what happen if I'll try to use it again in the future?
If I had use LightDM what would happen?
Why ubuntu didn't tall me about these updates after cleaning?
"Standard" components...? electronics.stackexchange.com
"Standard" components...? – electronics.stackexchange.com
In class we are designing a few different circuits and it uses some diodes
and opamps. Everything is fine on paper and everything makes sense. These
are only ever refereed to as a "diode" or "opamp". …
In class we are designing a few different circuits and it uses some diodes
and opamps. Everything is fine on paper and everything makes sense. These
are only ever refereed to as a "diode" or "opamp". …
Subscribe to:
Posts (Atom)