I have a form which uploads a photo to my database, and I use a view model to aid in this process.
View Model:
public class GalleryViewModel
{
//Members:
public Gallery _photo { get; set; }
public string _title { get; set; }[code]...
When I debug the code, I see that the in the post method in my controller, all the information from the form is updated in the view model except for the uploadFile which is null.In the form I use enctype = "multipart/form-data". When I use my master page the uploadFile is null but when I use the default MVC master page everything works fine.
My MVC 2 app includes a simple file upload within in a strongly typed view and I am trying to figure out how to apply model validation to the file name. Is this possible? Is there better way to do file upload within an MVC app?
The salient parts of the (prototype) controller code are:
[Code]....
The Create view code was generated with VS2010 and then modified to support file upload and client side validation:
I am working with ASP. net MVC project. There is File upload functionality to be implemented in the project. I am able to show the upload control using input-file. But I am not able to show defalut value (file with path) in text area using model binding.
Can we bind model to file upload control in MVC so that we can show Previous file (already uploaded) in the text area.
I'm trying to use below simple code for ajax postback. With file upload, neither javascript the "function startRequest" ever triggers, the file control shows null value somemore.Earlier I had Update progress which didn't work with file upload ever so I removed it. Now I just want to disable the button as the file is uploaded and its inputs are processed in the background. Once the response comes back, the "submit" button is re-enabled.But the file-upload with Updatepanel doesn't work at all. What am I doing wrong,
While Executing My Contact Management Asp.Net MVC application ,i am getting following error :
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[ContactManagementSystem.Models.EmployeeMaster]', but this dictionary requires a model item of type 'ContactManagementSystem.Models.ViewData.IndexModel'.
i having error throw on View page and i think i am passing wrong type.
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[App.Domain.Model.Interface.IPerson]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[App.Domain.Service.PersonService]'.
MyService looks like this....
namespace App.Domain.Service { public class PersonService : IPersonService [code].....
I have a asp.net mvc view which is strongly typed view and i have a controller which returnsthe ilist user based on the id provided. I am getting the following above error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Data.User]', but this dictionary requires a model item of type 'Data.User'.
I am new on MVC and i trying to learn it. My project its about a e-store...
But i got this error:he model item passed into the dictionary is of type 'baraMjukis.ViewModels.ProductViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[baraMjukis.ViewModels.ProductViewModel]'. And here are my code:
Calling Index view is giving me this very very annoying error . Can anybody tell me what to do about it
Error:The model item passed into the dictionary is of type 'System.Collections.Generic.List1[MvcApplication13.Models.Groups]', but this dictionary requires a model item of type 'MvcApplication13.Helpers.PaginatedList1[MvcApplication13.Models.Groups]'.
public ActionResult Index(int? page) { const int pageSize = 10; [code].....
I have a problem with dll. I have a class library and genrerated a dll. that dll has business entity object.If i pass value from front end t that dll.The value has not been accepted.Its remaining null after i passed the value
I am trying to use a fileupload, to add rows to my gridview on this page. This page is basically a simple admin panel where I can add data to my database. The file upload is used to grab the path of the file and upload the path to the database not the file. The problem is whenever i run my program pick a file, it uploads fine expect the path shows up as true not as the path. the gridview and details view both use the same sqladapater
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <br /> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>MSD</asp:ListItem> <asp:ListItem>OPS</asp:ListItem> </asp:DropDownList> <asp:Button ID="Button3" runat="server" Text="Department" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="New" /> <asp:Button ID="Button4" runat="server" Text="Cancel" /> <br /> <br /> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <center> <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="128px" Width="544px" Visible="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnModeChanged="Button1_Click" > <Fields> <asp:TemplateField HeaderText="Order" SortExpression="Order"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Order") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Order") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Order") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Department" SortExpression="Department"> <EditItemTemplate> <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Department") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="textboxdepartment" runat="server" Text='<%# Bind("Department") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("Department") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="DOC_Type" SortExpression="DOC_Type"> <EditItemTemplate> <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("DOC_Type") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="textboxtype" runat="server" Text='<%# Bind("DOC_Type") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label5" runat="server" Text='<%# Bind("DOC_Type") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> <asp:TemplateField HeaderText="Revision" SortExpression="Revision"> <EditItemTemplate> <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Revision") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Revision") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="textboxrevision" runat="server" Text='<%# Bind("Revision") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="DOC"> <EditItemTemplate> <asp:TextBox ID="textboxdate" runat="server" Text='<%# Bind("DOC") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:FileUpload ID="FileUploadDOC" runat="server" Width="384px" Enabled='<%# Bind("DOC") %>' /> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("DOC") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Active" SortExpression="Active"> <EditItemTemplate> <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label7" runat="server" Text='<%# Bind("Active") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Rev_Date" SortExpression="Rev_Date"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Rev_Date") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rev_Date") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Rev_Date") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" /> <asp:CommandField ShowInsertButton="True" ShowCancelButton="False" /> </Fields> <FooterStyle BackColor="#5D7B9D" BorderStyle="None" Font-Bold="True" ForeColor="White" /> <CommandRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True" /> <RowStyle BackColor="#F7F6F3" BorderStyle="None" ForeColor="#333333" /> <FieldHeaderStyle BackColor="#E9ECF1" BorderStyle="None" Font-Bold="True" /> <EmptyDataRowStyle BorderStyle="None" /> <PagerStyle BackColor="#284775" BorderStyle="None" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#5D7B9D" BorderStyle="None" Font-Bold="True" ForeColor="White" /> <InsertRowStyle BorderStyle="None" /> <EditRowStyle BackColor="#999999" BorderStyle="None" /> <AlternatingRowStyle BackColor="White" BorderStyle="None" ForeColor="#284775" /> </asp:DetailsView> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:BoundField DataField="Order" HeaderText="Order" SortExpression="Order" /> <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" /> <asp:BoundField DataField="DOC_Type" HeaderText="DOC_Type" SortExpression="DOC_Type" /> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> <asp:BoundField DataField="Revision" HeaderText="Revision" SortExpression="Revision" /> <asp:BoundField DataField="DOC" HeaderText="DOC" SortExpression="DOC" /> <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" /> <asp:BoundField DataField="Rev_Date" HeaderText="Rev_Date" SortExpression="Rev_Date" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" /> </Columns> </asp:GridView> <br /> </ContentTemplate> </asp:UpdatePanel> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CABCIntranetConnectionString %>" DeleteCommand="DELETE FROM [sop] WHERE [ID] = @original_ID AND (([Order] = @original_Order) OR ([Order] IS NULL AND @original_Order IS NULL)) AND (([Department] = @original_Department) OR ([Department] IS NULL AND @original_Department IS NULL)) AND (([DOC Type] = @original_DOC_Type) OR ([DOC Type] IS NULL AND @original_DOC_Type IS NULL)) AND (([Title] = @original_Title) OR ([Title] IS NULL AND @original_Title IS NULL)) AND (([Revision] = @original_Revision) OR ([Revision] IS NULL AND @original_Revision IS NULL)) AND (([DOC] = @original_DOC) OR ([DOC] IS NULL AND @original_DOC IS NULL)) AND (([Rev Date] = @original_Rev_Date) OR ([Rev Date] IS NULL AND @original_Rev_Date IS NULL)) AND (([Active] = @original_Active) OR ([Active] IS NULL AND @original_Active IS NULL))" InsertCommand="INSERT INTO [sop] ([Order], [Department], [DOC Type], [Title], [Revision], [DOC], [Rev Date], [Active]) VALUES (@Order, @Department, @DOC_Type, @Title, @Revision, @DOC, @Rev_Date, @Active)" SelectCommand="SELECT [Order], [Department], [DOC Type] AS DOC_Type, [Title], [Revision], [DOC], [Rev Date] AS Rev_Date, [Active], [ID] FROM [sop] WHERE ([Department] = @Department) ORDER BY [Order]" UpdateCommand="UPDATE [sop] SET [Order] = @Order, [Department] = @Department, [DOC Type] = @DOC_Type, [Title] = @Title, [Revision] = @Revision, [DOC] = @DOC, [Rev Date] = @Rev_Date, [Active] = @Active WHERE [ID] = @original_ID AND (([Order] = @original_Order) OR ([Order] IS NULL AND @original_Order IS NULL)) AND (([Department] = @original_Department) OR ([Department] IS NULL AND @original_Department IS NULL)) AND (([DOC Type] = @original_DOC_Type) OR ([DOC Type] IS NULL AND @original_DOC_Type IS NULL)) AND (([Title] = @original_Title) OR ([Title] IS NULL AND @original_Title IS NULL)) AND (([Revision] = @original_Revision) OR ([Revision] IS NULL AND @original_Revision IS NULL)) AND (([DOC] = @original_DOC) OR ([DOC] IS NULL AND @original_DOC IS NULL)) AND (([Rev Date] = @original_Rev_Date) OR ([Rev Date] IS NULL AND @original_Rev_Date IS NULL)) AND (([Active] = @original_Active) OR ([Active] IS NULL AND @original_Active IS NULL))" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}"> <DeleteParameters> <asp:Parameter Name="original_ID" Type="Int32" /> <asp:Parameter Name="original_Order" Type="Int32" /> <asp:Parameter Name="original_Department" Type="String" /> <asp:Parameter Name="original_DOC_Type" Type="String" /> <asp:Parameter Name="original_Title" Type="String" /> <asp:Parameter Name="original_Revision" Type="Int32" /> <asp:Parameter Name="original_DOC" Type="String" /> <asp:Parameter Name="original_Rev_Date" Type="String" /> <asp:Parameter Name="original_Active" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Order" Type="Int32" /> <asp:Parameter Name="Department" Type="String" /> <asp:Parameter Name="DOC_Type" Type="String" /> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Revision" Type="Int32" /> <asp:Parameter Name="DOC" Type="String" /> <asp:Parameter Name="Rev_Date" Type="String" /> <asp:Parameter Name="Active" Type="String" /> <asp:Parameter Name="original_ID" Type="Int32" /> <asp:Parameter Name="original_Order" Type="Int32" /> <asp:Parameter Name="original_Department" Type="String" /> <asp:Parameter Name="original_DOC_Type" Type="String" /> <asp:Parameter Name="original_Title" Type="String" /> <asp:Parameter Name="original_Revision" Type="Int32" /> <asp:Parameter Name="original_DOC" Type="String" /> <asp:Parameter Name="original_Rev_Date" Type="String" /> <asp:Parameter Name="original_Active" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Order" Type="Int32" /> <asp:Parameter Name="Department" Type="String" /> <asp:Parameter Name="DOC_Type" Type="String" /> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Revision" Type="Int32" /> <asp:Parameter Name="DOC" Type="String" /> <asp:Parameter Name="Rev_Date" Type="String" /> <asp:Parameter Name="Active" Type="String" /> </InsertParameters> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" DefaultValue="MSD" Name="Department" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:SqlDataSource> </div> </form> </body> </html> Imports System.Data.Sql Imports System.Data.SqlClient Imports System.Data Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click DetailsView1.Visible = True DetailsView1.ChangeMode(DetailsViewMode.Insert) Dim tbox As TextBox = TryCast(DetailsView1.FindControl("textbox1"), TextBox) tbox.Text = DateTime.Now.ToShortDateString() Dim tbox1 As TextBox = TryCast(DetailsView1.FindControl("textboxdepartment"), TextBox) tbox1.Text = DropDownList1.SelectedItem.Text Dim tbox2 As TextBox = TryCast(DetailsView1.FindControl("textbox6"), TextBox) tbox2.Text = "True" Dim tbox3 As TextBox = TryCast(DetailsView1.FindControl("textboxtype"), TextBox) tbox3.Text = "S.O.P" Dim tbox4 As TextBox = TryCast(DetailsView1.FindControl("textbox5"), TextBox) tbox4.Text = "1" Dim tbox5 As TextBox = TryCast(DetailsView1.FindControl("textbox2"), TextBox) tbox5.Text = GridView1.Rows.Count + 1 End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click UpdatePanel1.Update() End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click DetailsView1.Visible = False End Sub End Class
I was doing a project involving posting a new job site. How do you upload a .docx file to the server, and then allow viewer to view it later on the web.
I have a partial view FileUpload which contains a file control. <ul> <li> <label> <span>*</span>Select the file: [code]...
This partial view is added in view Document which have few textboxes to get detials of document. I need to upload the files and add file details to database using jquery also need to retain the values in the textboxes (which is to be saved in another "Save" click) after the upload function is called
I'm trying to develop my application and I've got a master page where I'm planning to create a div container, where my "news" will be loaded from my database and will be shown always on a main site. Then inside of the main placeholder I'm planning to load some extra data too from my database... and there's the question: how to solve that ? is there any possibility to pass a model to a master page ? or two viemodels to a view page inside the main placeholder on my page ? (one with news, and other containing some other data).
I am using the async file upload control to upload to a image file. I want the user to upload only jpg files. And for that I am checking the uploadedfile content type in server side, after the upload complets. I wanna check this, before upload starts. There is one javascript method
function startUpload(sender, args){}
but how to access the content type of the file selected by user.
I am trying to upload a text file and display the content in a grid view. However, when i try to upload it,it appear this error? Oh ya, do you know the code to upload text file? If you know can u edit my code to make it take the file from fileupload instead of textbox?
The error is:
Index was outside the bounds of the array. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.