Asp.net Mvc2 - DisplayFor Need Iteration-like Context?
Jan 15, 2010
In my app I have a criteria builder section that's built using jquery and is pitched back to the controller in a form post and picked up as IList by the model binder as suggested in Phil's post here: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx A really simple way that I'm persisting the criteria across posts is re-delivering the IList object to the view. I'm using a DisplayFor() template for this object, but because it's a list I need to know the index # inside of the template.
View 1 Replies
Similar Messages:
May 12, 2010
I need a way to show the display for an element in my list view like so:
[Code]....
Would it be possible to pass in a model to the DisplayFor method?
Maybe a syntax like this:
public static MvcHtmlString DisplayFor<TParentModel, TModel, TValue>(this HtmlHelper<TParentModel> html, TModel model, Expression<Func<TModel, TValue>> expression);
<%: Html.DisplayFor(item, i => i.BarBaz) %>
View 2 Replies
Jan 13, 2011
I have a list of Key/Value pairs. basically its a List where ViewModel is a custom class of the form
public class ViewModel
{
public String Key { get; set; }
public String Value { get; set; }
}
In the View i would need to render Label and Textbox for Key and Value respectively.Im trying to use Html.DisplayFor() however it goes with model and only displays the properties of the model and not the list.I would like to achieve something of the format
<% foreach (var item in Model) { %>
<tr>
<td>
<%:Html.Display("item")%> [code]....
View 1 Replies
Oct 21, 2010
Im using asp.net mvc 2. I have a model Supermodel that consists of 2 models TestModel1 and TestModel2. In SuperModelView Im doing the following thing:
<%: Html.DisplayFor(x=> x.TestModel1, "TestModel1Template") %>
Its working just fine, except for the fact, that dropdownlist is populated but selected value is not set.Im using the following code for a dropdownlist in my template:
<%: Html.DropDownListFor(x=> x.Property1, (IEnumerable<SelectListItem>)ViewData["MyDDLList"], Model.Property1) %>
and its not setting the selected property. I put the code below to SuperModelView, that calls <%: Html.DisplayFor To populate the template and it works just fine.
<%: Html.DropDownListFor(x=> x.TestModel1.Property1, (IEnumerable<SelectListItem>)ViewData["MyDDLList"], Model.TestModel1.Property1) %>
UPDATE: I`ve tried to investigate the issue, but something is totally wrong. I can share the whole code, not sure where to put it, here or attach with separate files.
@Darin, what other parts should I share, or just share the whole model view and controller files?
View 1 Replies
Jun 21, 2010
i use the Html.LabelFor method for displaying the property names and Html.DisplayFor for the property values of my model.
Unfortunately i cannot use the following format:
Title: value...
Description: value...
since the LabelFor method inserts a line break, so the result returned is like:
Title
: value...
Description
: value
How could i get rid of the extra line break?
View 6 Replies
Sep 29, 2010
using c#.net/asp.net
new to C# question: I am in an iteration of a for loop and if a condition exists I want to jump to the next iteration of the for loop, how do I do this in C#?
View 1 Replies
Oct 13, 2010
I have List (of class). having 1800 of count and each object has 90 properties. When I terate earch with 90 properties taking more and more time. How to resolve this
Dim cellIntStyle As HSSFCellStyle = hssfworkbook.CreateCellStyle
cellIntStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#")
Dim cellDateStyle As HSSFCellStyle = hssfworkbook.CreateCellStyle
cellDateStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat(Format
("dd-MMM-yyyy"))
For Each mReport As Report In dtExcel
row = sheet1.CreateRow(iRow)
j = 0
For Each prop As PropertyInfo In props
Dim value As Object = prop.GetValue(mReport, Nothing)
If IsInt(value) Then
CreateRow(row, j, CType(value, Integer), cellIntStyle)
ElseIf IsDate(value) Then
CreateRow(row, j, String.Format("{0:dd-MMM-yyyy}",
value), cellDateStyle)
Else
CreateRow(row, j, value)
End If
j = j + 1
Next
iRow = iRow + 1 // Coming here taking so long... how to make it fast.
Next
Private Sub CreateRow(ByRef row As HSSFRow, ByVal colId As Integer,
ByVal value As String)
row.CreateCell(colId).SetCellValue(value)
End Sub
Private Sub CreateRow(ByRef row As HSSFRow, ByVal colId As Integer,
ByVal value As Integer,
ByVal cellStyle As HSSFCellStyle)
Dim cell As HSSFCell = row.CreateCell(colId)
cell.SetCellValue(value)
cell.CellStyle = cellStyle
End Sub
Private Sub CreateRow(ByRef row As HSSFRow, ByVal colId As Integer,
ByVal value As String,
ByVal cellStyle As HSSFCellStyle)
Dim cell As HSSFCell = row.CreateCell(colId)
cell.SetCellValue(value)
cell.CellStyle = cellStyle
End Sub
View 4 Replies
Jul 21, 2010
I've got a while loop that's doing some stuff, and what I want is for it to create a new array each time.
while(condition){
//do some stuff
//create an array x[]
//amend values in array
//save as new array each time until loop finished
}
Actually i need to store the comma separated values of different datatypes in an array using split.And then i hav to sort these values comparing zeroth position element of all rows.
View 3 Replies
Jan 18, 2011
Is it possible to detect or use a different template in the asp.net repeater for the last iteration in the repeater?If not I could just use a for loop but I'm curious if it can be done.
View 2 Replies
Nov 19, 2010
i want to insert iteration elements(Signal) according my requirement like below xml output.
<?xml version="1.0" encoding="UTF-8"?>
<WIUConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> [code]...
how i can achive this iteration concepts using C#.net LINQ to XML.Here is my Code:
XDocument xdco = new XDocument(
new XDeclaration("1.0", "utf-8", "Yes"),
new XComment("WIU Configurations"),[code]...
from above code how to insert iterate element with XML file?
View 2 Replies
Mar 8, 2011
I'm doing some custom code for a SharePoint webpart in C#. Specifically, I'm making a quiz, my main point here addressing the list that holds the question, answer choices, and correct answer.
At the last stage of the quiz I need to check the answers selected by the user against the correct answer in the list. Currently, I'm doing the following to check if each is correct, which I'm assuming isn't very efficient because it iterates through each question. Is there a method, specifically for the SPList foreach loop, that would be more efficient?
// 1. Store questions and answers in class
List<submittedAnswers> answeredQuestions = new List<submittedAnswers>();
// 2. From POST pull answered question IDs and answer IDs (which correspond to the question primary key and answer choice number both stored in the list)
// INSERT BEAUTFIUL AND EFFICIENT WHILE LOOP HERE
// 3. Loop through each question is list, if question was given, test if correct/incorrect
using (SPWeb myWeb = mySite.OpenWeb())
{
SPList answerList = myWeb.Lists[questionList];
foreach (SPListItem quizEntry in answerList.Items)
{
int pullAnswerId = int.Parse(quizEntry["Answer"].ToString()); // Pull answer number from list
int pullQuestionId = int.Parse(quizEntry["ID"].ToString()); // Pull primary key of question
submittedAnswers result = answeredQuestions.Find(delegate(submittedAnswers e) { return e.questionId == int.Parse(quizEntry["ID"].ToString()); });
if (result != null)
{
if (result.responseId != pullAnswerId) // If the response was different from the answer
incorrectAnswers++;
else
correctAnswers++;
}
}
}
// C# quiz grading magic here....
View 4 Replies
Mar 22, 2010
I have made an asp.net website which is using master page in it.
my programming language is c#. I want to iterate through content page controls but i m not able to do it. I have searched a lot on internet but of no avail.
View 1 Replies
Oct 5, 2010
I think this is something really easy that I am missing. I have a loop that is sending emails. The loop adds an attachement from a FileUpload instance. The first run of the loop is fine but each subsequent run the attachment is empty. I have found mention of reseting contentstream.position to 0 but that doesn't seem to apply to the FileUpload control. I am attaching the code below.
[Code]....
View 2 Replies
Jan 13, 2010
I'm writing an update script that goes through each record and performs various updates, and I want the current record to display while it's processing.
For Each row As DataRow In DS.Tables(0).Rows
'Label Inside Ajax Panel
Label_Ajax.Text = row.Item("product_id").ToString
'Label Inside Ajax Update Progress Panel
Dim newlabel As Label = UpdateProgress1.FindControl("Label_AjaxProgress")
newlabel.Text = row.Item("product_id").ToString
' Tried straight to console, but doesn't work
Console.Write(row.Item("product_id").ToString)
Next
I've tried all three methods shown above, but they all end up displaying the last record after the iteration is complete. How can I get the current record to display on the screen during the iteration?
View 1 Replies
Jan 24, 2010
I have written simple HttpModule. context.Response.Output.Write is working fine. but not context.Response.Write().
View 2 Replies
Oct 14, 2010
My Question is can we extend one context to another in Entity Framework 4. Following is the problem background.
I am using EF4 for developing a Web-Application. My Web Application has 3 projects.
One project is for storing candidate CV information.
Another project is for storing customer information.
Final project is called CORE. this CORE contains a edmx file that should be extended by CV and CRM.
As an example email address table can be shared by both customer (CRM) and CV. To share one table with another, we should be able to extend one context (CV context) with other context (customer context). Could some one having experience using Entity Framework share your experience with me to find whether this is possible.
We have 3 edmx files in three class libraries:
Person class library(Core) with core.edmx-Basic details related to a person(name, email) CV Class library with CV.edmx wich have CV related data(Experiance,skills) Customer Relationship management system(CRM) which have customer data(sales data...)
Then we want to use core class library edmx file(Core.edmx) with cv.edmx (basically cv tables should be able to use tables from core tables) . Same way we want to use the core.edmx with CRM.edmx for the 3 rd project
View 1 Replies
Oct 8, 2010
i'm trying to encode an url with the code below;
var encodedUrl = HttpUtility.UrlEncode("http://www.example.com");
var decodedUrl = HttpUtility.UrlDecode("http%3A%2F%2Fwww%2Eexample%2Ecom%2F");
I'm working with the google webmaster tools api and this api expects an URL as shown in the decodedUrl variable above. Every single character is encoded there.
When i use the httputility encode function i get the following result;[[URL] How can i use the encoding variable in such a way that every character in the url is encoded?
View 2 Replies
Mar 2, 2010
[HttpPost]
public ActionResult Edit(int id, FormCollection fc)
{
Movie movie =
(
from m in _ctx.Movie.Include("MovieActors")
where m.MovieID == id select m
).First();
MovieActorViewModel movieActor = new MovieActorViewModel(movie);
if (TryUpdateModel(movieActor))
{
_ctx.ApplyPropertyChanges(movieActor.Movie.EntityKey.EntitySetName,
movieActor.Movie);
_ctx.SaveChanges();
}
return View(movieActor);
}
However, I am not sure how to test this, and in general would much rather have the method take a typed model like:[HttpPost] public ActionResult Edit(MovieActorViewModel movieActor) Is this possible? What changes to my MovieActorViewModel class do I need to make in order to enable this? That class looks like this:
public class MovieActorViewModel
{
public Movie Movie { get; set; }
public Actor Actor { get; set; }
public PublisherDealViewModel(Movie movie)
{
this.Movie = movie;
this.Actor =
(
from a in this.Movie.Actors
where a.ActorID == 1 select a
).First();
}
}
The view is typed (inherits ViewPage) simple:
<% using (Html.BeginForm()) {%>
Movie Title: <%= Html.TextBoxFor(model=>model.Movie.Title) %><br/>
Actor Name: <%= Html.TextBoxFor(model=>model.Actor.Name) %>
<% } %>
View 3 Replies
Feb 8, 2011
I tried upgrading the solution to MVC3 in VS2010 by using an upgrader tool I don't know what it does exactly but it didn't work. My "System.Web.Mvc" is not being recognized in my project. Is there anything specific I should be doing with my web.config? I don't quite understand the underlying details about all the places I should be referencing dll's or what "binding" even means and when I should use it inside the web.config So I have to ask, what is the best method for upgrading to MVC3 and what have you done that works?
View 1 Replies
Apr 29, 2010
I've spent the majority of the past week knee deep in the new templating functionality baked into MVC2. I had a hard time trying to get a DropDownList template working. The biggest problem I've been working to solve is how to get the source data for the drop down list to the template. I saw a lot of examples where you can put the source data in the ViewData dictionary (ViewData["DropDownSourceValuesKey"]) then retrieve them in the template itself (var sourceValues = ViewData["DropDownSourceValuesKey"];) This works, but I did not like having a silly string as the lynch pin for making this work.
[code]...
View 3 Replies
Mar 25, 2010
I am trying to figure out how to get the DisplayAttribute in my MVC 2 ViewModel to work with the Html.LabelFor() helper.
Neither
public class TestModel
{
[Display(ResourceType = typeof(Localization.Labels))][code]...seem to work. Localizing the Required Attribute works as expected:
[Required(ErrorMessageResourceName = "Test", ErrorMessageResourceType = typeof(Localization.Labels))]
I am using VS2010 RC. Has anybody got that running?
View 3 Replies
Nov 16, 2010
I have an MVC2 .NET 4.0 app, hosted on TFS 2008 (soon to be TFS 2010) that uses connection strings in web.config to connect to a database on another server. I need to encrypt these connection strings.
As I understand it, I can use aspnet_regiis.exe to encrypt the connectionstring portion of the web.config file, but I have to do it on the deployment machine because the encryption uses the machine name to generate the encryption key.
Now, it seems to me that this represents a problem - every time I deploy my code to the dev server won't it overwrite the web.config file, and need to be re-encrypted? This sort of manual process seems kludgy.
Is my understanding about needing to re-encrypt after deployment correct? If so, is there some way to automate this process? I don't want to forget this or get a new team member who doesn't know the process and have the connectionstring exposed to the world.
View 1 Replies
Jun 28, 2010
For my project, i need to connect to a database who don't support ADO.net by using NHibernate
So, is it possible to make my own model who can be usable by the auto-creation of views of visual studio 2010 ?
View 2 Replies
Mar 3, 2011
I have this code in my view page.
<td>
Mandate Name:
</td>
<td>
<%= Html.TextBox("MandateName")%>
</td>
I wrote MVC2 Validation for this name.
something like this.
//[Validator(typeof(MandateValidator))]
[MetadataType(typeof(Mandate_Metadata))]
public partial class Mandate {
public class Mandate_Metadata
{.........
View 2 Replies
Apr 24, 2010
I've tried this guide: http://mvcsitemap.codeplex.com/Thread/View.aspx?ThreadId=208090I've added dll "MvcSiteMap.Core.dll" i referencesAnd I've added namespaces in web.config: "<add namespace="MvcSiteMap.Core" />"When I'm entering the web page comes this message:
Line 49: </runtime>Line 50: Line 51: <siteMap defaultProvider="MvcSiteMap">Line 52: <providers>Line 53: <add
View 3 Replies