Click here to Skip to main content
15,887,676 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Bad Behavior Pin
Nathan Minier16-Jun-16 1:18
professionalNathan Minier16-Jun-16 1:18 
GeneralRe: Bad Behavior Pin
BobbyStrain16-Jun-16 6:24
BobbyStrain16-Jun-16 6:24 
GeneralRe: Bad Behavior Pin
Nathan Minier17-Jun-16 1:57
professionalNathan Minier17-Jun-16 1:57 
GeneralRe: Bad Behavior Pin
BobbyStrain17-Jun-16 5:50
BobbyStrain17-Jun-16 5:50 
Question@Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14314-Jun-16 10:02
indian14314-Jun-16 10:02 
AnswerRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
jkirkerx15-Jun-16 7:24
professionaljkirkerx15-Jun-16 7:24 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14315-Jun-16 8:06
indian14315-Jun-16 8:06 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
jkirkerx15-Jun-16 13:09
professionaljkirkerx15-Jun-16 13:09 
If your model is not showing up in intellisense, then you need to reference that model in the view

So let's pretend this is a view file. I created my Model in a class with the namespace Indigo.Entities.Models so in the first line in the view, I add ...
@using Indigo.Entities.Model
In the 2nd line, I make a reference to the Model
@model model_customer_Addresses

So now it looks like this
@using Indigo.Entities.Models;
@model model_customer_Addresses

@{
    ViewBag.Title = @Model.Name + "'s Addresses";
    Layout = "~/Views/Shared/Admin/_adminLayout.cshtml";
}

So what is the model? Think of it like a custom container or lunch box. In the lunch box you declare a sandwich, fruit and beverage. You build or declare the model in the controller, then pass the model to the view. The view knows that the model says you have to have all 3 in the lunchbox, and will not let you post the page until all 3 are selected; Validate! once validation is complete, the page will post the model back to the controller which can then pass the model to the database to write a record.

On the form, you create 3 elements, 1 assigned to sandwich, 1 to fruit, 1 to beverage.
Wrap it in a form element, add a submit button, some validation and your done!

As far as Html helpers goes, they are Razor, which creates shortcuts for writing HTML Elements. In other words, all they do is generate HTML. The benefits to using Razor is organizing the
Text, Action and Controller. and it also aids in Url routing. The rendering engine will figure out how to construct or code the URL, and the controller will figure out how to read or decode the Url.

My first MVC project was so hard to learn. I had no clue what I was doing and wondered it it was worth it. Now I'm on my 3rd project and it's well worth it. I'm not going back to web forms.

But be careful using Razor. I'm using less and less of it now.
Consider this, you can use razor to write an ActionLink, or just write an A element
<a class="btn btn-primary" href="@Url.Action("AddressesBilling", "Admin", new { caID = Model.CustomerID, baID = address.BillingID })" data-toggle="tooltip" data-placement="bottom" title="Edit the customers billing address" data-original-title="Edit the customers billing address">Edit</a>
This creates a button using the A element or hyperlink, but I was still able to use Razor to calculate the Url that has routing attached to it. The bootstrap turns the hyperlink into a button.
indian143 wrote:
I am new to ASP.Net MVC, do I need to create all those html helper classes, it is very confusing for me now I am used to that drag and drop in Web Forms design. Now it seems I need to learn lots of lots of things.

Not really, just write great HTML and then fill in the spaces using Razor. Razor is tricky, like the @ char rules. Once you declare @, you don't have to use it again in the same line. Just watch the Yellow markers that will help you.
indian143 wrote:
And just asking one more thing why is the model and ViewBag are also showing errors as model and ViewBag are not recognizable objects. How can I resolve that issue? Why is that issue coming I am not sure at all.

I don't use the ViewBag, I make better models that include everything I need. The hardest part of MVC is designing the models. Models have to be reusable, compact, not duplicated, organized which is very important.

You have to change the way you think about organizing data. And constantly update your models to be more reusable until your really good at it.

Like take a customer for instance. The customer will have an account name, email address, password, date. but perhaps the customer will have an address as well. So you create a model called address or something.

your model would be
name
email
password
date
address as model_address below
and the address model would be
address1
city
state
country
stateList - List of states for dropdown
countryList - List of countries for dropdown

Hope that helps!
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14315-Jun-16 23:05
indian14315-Jun-16 23:05 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14316-Jun-16 9:08
indian14316-Jun-16 9:08 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
jkirkerx16-Jun-16 10:37
professionaljkirkerx16-Jun-16 10:37 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14316-Jun-16 16:52
indian14316-Jun-16 16:52 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14316-Jun-16 22:45
indian14316-Jun-16 22:45 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
jkirkerx17-Jun-16 5:54
professionaljkirkerx17-Jun-16 5:54 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
indian14317-Jun-16 9:15
indian14317-Jun-16 9:15 
GeneralRe: @Url is saying "the name url doesn't exist in the current context" ASP.MVC 4 Pin
jkirkerx19-Jun-16 7:07
professionaljkirkerx19-Jun-16 7:07 
Question.NET Oracle.DataAccess.Client Pin
Karan_TN14-Jun-16 3:52
Karan_TN14-Jun-16 3:52 
AnswerRe: .NET Oracle.DataAccess.Client Pin
John C Rayan14-Jun-16 4:22
professionalJohn C Rayan14-Jun-16 4:22 
Question.net Pin
Member 1257929012-Jun-16 7:59
Member 1257929012-Jun-16 7:59 
AnswerRe: .net Pin
Richard MacCutchan12-Jun-16 23:00
mveRichard MacCutchan12-Jun-16 23:00 
AnswerRe: .net Pin
F-ES Sitecore12-Jun-16 23:32
professionalF-ES Sitecore12-Jun-16 23:32 
AnswerRe: .net Pin
Richard Deeming13-Jun-16 2:05
mveRichard Deeming13-Jun-16 2:05 
GeneralRe: .net Pin
ZurdoDev15-Jun-16 9:40
professionalZurdoDev15-Jun-16 9:40 
AnswerRe: .net Pin
John C Rayan14-Jun-16 4:24
professionalJohn C Rayan14-Jun-16 4:24 
Question.net Pin
Member 1257929012-Jun-16 7:57
Member 1257929012-Jun-16 7:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.