Asp.net MVC3 Appropriate Model Passing

May 24, 2012

I'm quite new to MVC and while I've been trying to follow the best practices , I believe I may not be understanding certain fundamentals of either

-a. Using models and viewmodels appropriately

-b. Passing models into a controller for validation purposes.

The general purpose of my program is to select a stored procedure from a list of stored procedures, create a form where the user can fill out all the appropriate input variables, and then to execute that stored procedure. The tool is for non-technical people, so I'm eventually going to have to do a good deal of input validation.

As such I have four models: A Script Model, a Parameter Model, a Parameter Enum model and a Query Model, and two viewmodels: a paramviewmodel that generates the form to fill out, and a scriptviewmodel that creates a listbox filled with the possible script choices. I am using a prewritten database system to fill out my viewmodels in an init method in my controller (which I'm not sure is the proper way to do this?).

The viewmodels are as follows:

Imports System
Imports System.Collections.Generic
Public Class ScriptViewModel

[Code]....

I'm trying to work out the functionality. Also, I think this may be too much code in the view, even though most of it is display code.

Anyways, I have two main questions. One, does creating a model in my controller, calling an init method on it, and then passing it to the view make any sense in an mvc context (if not, how would I proceed?). Two, if I want to perform validation on the form I output in my htmlhelper, but I want to use my query model validation (and not my paramviewmodel), how can I do that? Most of the examples I've seen involve a controller that recieves an appropriate model variable, and the binding is performed outside the controller itself. They then just check modelstate. Is there any way I could do something similar here?

Edit: Is there any way I can make the syntax highlighting less crappy?

View 1 Replies


ADVERTISEMENT

Passing Data From WinForms Application To MVC3

Dec 14, 2011

I am working on an application that has a Winforms and MVC3 Web component. We need to be able upload large files from the desktop to the web. I have tried the various VB 2010 WebClient and FTP FileUpload alternatives but continue to run into permission issues, even though the User-ID and password I supply are the same as those used by an FTP application that successfully copies files to the same MVC3 site. In my efforts to find alternative solutions, I have looked into using WCF which also seems complicated and problematic for this particular application.

The closest I have come to a solution utilizes HttpWebRequest on the Winforms application. The following VB 2010 and C# code (MVC3) successfully passes the Filename and File data to MVC3 (the InputStream contains the references and UrlEncode data, but the class containing the fields for this data are null. (I have also passed just the file data without the filename, and the uploaded file is successfully created from the InputStream - but the method variable is still null). Although I could pick apart the InputStream, I would prefer a more elegant alternative.

VB 2010 Winforms method:
Public Shared Sub FileUpload(ByVal Filepath As String)
Try
Dim Host = System.Configuration.ConfigurationManager.AppSettings("Host")
Dim url As String = Path.Combine(Host, "UI/FileUpload")
Dim request As HttpWebRequest = HttpWebRequest.Create(url)
request.Method = "POST"
[Code] .....

View 2 Replies

ASP.NET MVC3 - Append A Dot To The Code?

Apr 16, 2011

With the MVC3 Razor synax, one may render a string like so

@ViewData("photo")

My problem is: How can I append a dot to the above code.The following will result in a "Public member 'jpg' on type 'String' not found.

@ViewData("photo").jpg

I've tried the following code but does not produce my intended result:

@ViewData("photo") .jpg
@ViewData("photo"):.jpg
@ViewData("photo") & ".jpg"

View 3 Replies

File Uploading In Asp.Net MVC3?

Apr 12, 2012

I'm trying to implement a file upload system and I don't really get what to do.

I'm looking for the easiest way to do it. After long researches, I've found those explanations.

forums.asp.net/t/1678157.aspx/2/10

So, here is the things I've done inside the view :

@Code
Dim fileName As String = ""
If (IsPost) Then

[Code].....

Problem : GetHtml is not a member of 'System.Web.UI.WebControls.FileUpload'
What can I do to fix this? Is it the good way to handle file uploads?

View 2 Replies

MVC3 DropDown List?

Apr 2, 2012

Function Monitor() As ActionResult
Dim db = New QuarterDBContext()
Dim items As IEnumerable(Of SelectListItem) = db.getQuarter.[Select](Function(c) New

[code].....

View 1 Replies

Resource Not Found - MVC3

Nov 2, 2011

Having issues getting myself started on MVC3.Trying to define a simple route here in Global.asax [code]

View 3 Replies

.net - ASP.Net MVC3 Display Sql Output In Webgrid?

Feb 3, 2011

I am using ASP.Net MVC3 with MySQL Trying to figure out beast way to return sql result from controller to view and display output using webgrid help class.

tried following its not working.Controler code

data = New DataTable
da = New MySqlDataAdapter("SELECT * FROM " + tables.SelectedItem.ToString(), conn)
cb = New MySqlCommandBuilder(da)
da.Fill(data)
ViewData("grid") = data

[Code]...

View 1 Replies

.net - Implementing MS Charts In ASP.NET MVC3 Project?

Nov 16, 2011

I have a MVC application, which creates a Chart in the business logic like this:

StatisticsModel.Chart.Width = 150
StatisticsModel.Chart.Height = 300
StatisticsModel.Chart.Attributes.Add("align", "left")
StatisticsModel.Chart.Titles.Add("Statistics for: " + StatisticsModel.ProductNumbers)
StatisticsModel.Chart.ChartAreas.Add(New ChartArea)

[Code]...

View 1 Replies

Asp.net - Action That Returns A File In MVC3?

Apr 19, 2012

So, I don't get what I still should to to make a file downloadable within the action.

So, here is the controller that I have. Everything seems to work fine, except that I never receive any file to download client-side.

<HttpPost()>
Function meetingCP(idCont As Integer, idOpp As Integer, schedule As String) As FileResult

[Code]....

View 3 Replies

Make MVC3 DropDown List?

Apr 14, 2011

Function Monitor() As ActionResult
Dim db = New QuarterDBContext()
Dim items As IEnumerable(Of SelectListItem) = db.getQuarter.[Select](Function(c) New

[code].....

View 36 Replies

Mvc - MVC3 Razor SelectedValue In DropdownListFor?

May 30, 2012

I've the following code for a DropDownListFor and is working ok

@Html.DropDownListFor(Function(model) model.Habilitacoes, New SelectList(ViewBag.Habilitacoes, "KeyHL", "DescricaoHL"), New With {.class = "FillHSpace"})

[code].....

View 2 Replies

MVC3 VB: Sort By Date And Time?

Mar 22, 2012

I have table with date/time column and person column. Each person has multiple records for each day. What I need to do is next: I need to get first record for each person for each day... Can this be done in MVC3 Visual Basic and Entity framework?

View 2 Replies

Asp.net Mvc - Getting Number Of Connections Currently Viewing Mvc3 Application

Jan 24, 2012

MVC3 vb.net Application using built in session management. I have an mvc3 application that I would like to add being able to see the current number of users online to whether they are logged in or not. I have tried using: Membership.GetNumberOfUsersOnline.ToString But that only keeps track of current users logged in which is not acceptable in what I am trying to do. Is there any other method that keeps track of connections?

View 1 Replies

Asp.net Mvc 3 - .Net, MVC3, And Razor - Modifying ActionLink Helper?

Jun 21, 2011

How do I modify or create my own Html.ActionLink helper to accept and handle the first parameter (linkText) passed in as an empty string / nothing?Details: I currently have a strongly typed view that's passed a model which contains search results. My view loops through each item in the model and attempts to display a link to a contact with the following code:

@Html.ActionLink(currentItem.ContactName, "contact", "details", New With { .id = currentItem.ContactID }, Nothing)

Normally this would work just fine, but not every item in my search result has a ContactName. The Html.ActionLink helper errors when this first parameter is empty. In case it helps, here's the model property for ContactName (which is generated from a template due to Database First, so I don't believe it can be modified):

Public Property ContactName As String

I'd like to have a helper function that simply returns nothing if the ContactName is an empty string / nothing.I'm guessing I need to extend this helper, and I've struggled to find any good, up-to-date resources in VB.net for extending helper functions. Other approaches are more than welcome if they're considered best practice. I'm working in VB.net, MVC3, and Razor in the ASP.net 4.0 framework.

View 2 Replies

Asp.net Mvc 3 - Late Binding Issue With MVC3 ViewBag?

Feb 18, 2011

I'm trying out MVC Scaffolding in a VB.NET MVC3 project and running into an issue with late binding with Option Strict set on (and I want it on).

This works in C#:

public ActionResult Create()
{
ViewBag.PossibleTeams = context.Teams;

[code].....

causes the compiler error Option Strict On disallows late binding. I took a look at the documentation here: [URL] but it wasn't very helpful.

I notice that a new empty application in C# uses the ViewBag in the HomeController but the VB.NET version uses ViewData, so maybe this is a VB.NET limitation.

View 2 Replies

Namespace Reference In .NET MVC3 Razor View In VB?

Jan 25, 2011

How do I reference a Namespace in .NET MVC3 with the Razor view engine?

I understand this can be done in C#:

@using Namespace;

However in VB this doesn't seem to work:

@Imports Namespace

(i'm talking about inside a .vbhtml file)

View 1 Replies

Stored Procedure MVC3 Error On Execution

Apr 7, 2011

I got a stored procedure that reads a table and insert those data to antoher table. That's the way how it works because the first table imports data from excel using a package with SSIS.In EF4 I imported the SP and create function import:This SP has 2 IN variables and 2 OUT varibales.The IN varibales are parameters and OUT variables are a message and the number of records created.[code]

View 1 Replies

Add Loading Message Partial View Jquery Mvc3?

May 1, 2011

i have a pretty simple registration wizard form. this is an mvc3 azor project written in vb.my last step displays a partial view with the user's entered details. since the partial can take a split second to load, the form looks odd until it does - a blank form with a couple of buttons. is there a clean, proper way to display a little loading image/message while the partial is loading so it's obvious to the user he/she needs to hold on a sec.

my code for the register view:

$(function () {
$(".wizardstep:first").fadeIn(); // show first step
// attach back button handler

[code]....

the partial view for now is just a dummy display of the model elements.

View 1 Replies

MVC3 / RequireHttps And Custom Handler Result In Http 310

Apr 12, 2012

I'm trying to build a web application that uses an SSL connection. So I did some research and found out that I could use the RequireHttpsAttribute class to achieve what I needed. Thing is that when I use it, the execution of the application results in an 310 error(too many redirections). I even built a custom class to handle the switch from http to https. [code]

View 2 Replies

Telerik Grid Not Rendering Dropdownlist In Column MVC3?

Sep 3, 2011

I have a problem with the Telerik grid that I can't seem to find quite the exact problem anywhere. I'm following the demo from their site for Client Side Edit Templates. When going into edit mode it immediately dies saying select method is undefined from this js statement:

[Code]...

View 2 Replies

.net - Entity Framework 4.1 Code First+MVC3 And Accessing Entities Of A Certain Type?

May 13, 2011

I am using Entity Framework 4.1 code first+MVC3 and the inheritence stratagy that I use is TPC

I have the following classes
Public Class ObjectBase
<Key()>
Public Property Id As Integer
Public Property Description As String
End Class

[Code]...

Question 1 (and question 2) should be very simple, but I have allready spent hours on Google to find an answer with no result at all. The only thing I have found is that you can get all computers in ObjectBase by writing context.ObjectBase.OfType(Of Computer), and that does not help since you cannot write context.BorrowObjects.ObjectBase.OfType(Of Computer) code samples in VB.NET (if you can), but more importantly: Please ensure that the codesamples you supply work without hours of modification!

View 2 Replies

Increment Local Variable Inside Razor Syntax, MVC3

Sep 21, 2011

I am working on MVC3, i have a situation where i want to do something like this:

<Div>
@Code
Dim i = 1

[Code]....

but razor is throwing wrong syntax error message. how to do this properly in side razor code.

View 1 Replies

Keeping Browser From Timing Out In Mvc3 App During Long Processing Time

Mar 14, 2012

MVC3 vb.net. In my app I have a point where 500+ emails with attachments are sent out using a for each loop to accomplish this.. Nothing is returned to the browser the entire time this is running so eventually the browser think it has timed out... I tried just having it redirect to another actionresult function after every email and that function just passes it back to the email function. This is not working and I feel the reason is that nothing is actually being sent to the browser window its self.. Is there a way to fix this issue??

[Code]...

View 3 Replies

MVC3 Json: A Potentially Dangerous Request.Form Value Was Detected From The Client

Nov 8, 2010

I use... $.post("/StoreHtml", { 'html': $("#txtHtml").val(), , function (data) { }); to store html user enters, but method above fails with an "A potentially dangerous Request.Form value was detected from the client". How do I encode the html before sending it? ... and how do I decode it in vb.net?

View 2 Replies

.net - Circular Dependency Between MODEL And BLL?

Sep 1, 2011

Assuming an architecture as such.MODEL > BLL > DLL

Trying to implement lazy loading in my MODEL I have run into a circular dependency between my MODEL and BLL..Basically imagine a property in my model that I want to implement as follows

Public Readonly Property ProjectCategory As ProjectCategory
Get
If Me._ProjectCategory Is Nothing Then
Me._ProjectCategory = ProjectCategoryBLL.GetProjectCategoryByID(Me._ProjectCategoryID)
End If

[Code]...

I have my MODEL, BLL and DLL in separate projects and because of the fact that my BLL references my model I can not reference my BLL from my model as this would create a circular dependency.

View 3 Replies

Best Way To Implement A Certain Part Of Model

Feb 13, 2011

I am trying to figure out the best way to implement a certain part of my model.I have an entity named Customer which has CustomerLocations (1-*) which have SalesOrders (1-*) which have Invoices (1-*).I want to allow them to have multiple addresses (Billing and Shipping) per customer and per location. I want to store those values in the sales orders and invoices, not a foreign key, what if they delete one of their addresses later down the road.I have tried complex types, but then they can't have multiple, can they? And having an Address entity, customer --> address (1-*) is ok, but a bit clumsy. How would you have a collection of billing and shipping addresses.?

View 1 Replies

Best Way To Use NHibernate With The Repository Model

Mar 16, 2009

I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I use NHibernate to do the work on my business entities. For example:

[code]...

However, on my User class I have some properties and collections of other objects that ideally I'd like to be lazy loaded. But of course, the ISession is created and disposed within the repository, which I guess is why, outside of that, when I try to access those properties I get a "Could not initialize proxy - no Session" error.Is my only option then to disable lazy loading when using repositories? Or is it possible (or just foolish) to somehow get the session into scope in the business layer?I do like the repository model, and NHibernate is growing on me (after lots of initial frustration trying to make it work), so what's the best way you gurus have found of using them together?

View 1 Replies

ComboBox Value - Each Model # Correspond With A Different Id #

Mar 27, 2010

Hey I am a newcomer to Visual Basic. I am using VB 2008 Express. My problem is I have a combo box filled with model #'s and I would like to have each model # correspond with a different id #, but I have no idea on how to do this, and I have found no documentation on it.

View 8 Replies

Dynamically Set An Item In A Mvc Model?

Jun 19, 2012

how to phrase my question, but what I am trying to do is inside a for each loop set the item of a model then set the value of that item.

dim td as new project.model.mymodel create model object
For each dr as datarow in dt.rows
dim itemName as string = convert.tostring(dr("Field"))
td.itemName = "6"
next

I keep getting an error that itemName is not part of collection td

View 2 Replies

Get Model For Currently Selected Printer?

Mar 29, 2012

I have a program that prints raw code to Zebra printers. We are adding some Intermec printers. So I would like to be able to pull the Model of the Printer (selected from a standard printer dialog) and use that to chose the code that would be sent to the printer.

View 8 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved