none
MVC 4 dev with Visual Studio 2013 RRS feed

  • Question

  • Hello  My name is Ricky 

       I am currently taking a SAMS course on ASP.NET MVC 4. The class it self uses Visual Studio 2012 for the examples.

    The problem I have is in Lesson one part 2  Handle querystring variables.

    The Code is written like this

            index(string text)

    Viewbag.DisplayText = Text

    return  View();

          When the app is ran it is suppose to display text from the querystring on the page 

    localhost:xxxx/(name of the controller)?Text=Helloquerystring 

     Helloquerystring is what  suppose to be display instead of Hello World.

    How ever in Visual Studio 2013 the code is written like this 

     Function Index(string text) As ActionResult

            ViewBag.DisplayText = text





            Return View()

    it tells me for string (Keyword is not valid as an identifier )

    for text it tells me (System.Text is a namespace and cannot be used as an expression).

    I do have update 3 installed, and I am puzzled as to why these errors  keep popping up.

    Any advice would be helpful

    Thank you

    Sunday, August 31, 2014 11:19 PM

Answers

  • Are you using C# or VB.NET? It seems like you are mixing programming languages here.

    In a C# ASP.NET MVC Application you should use the following code:

        public class HomeController : Controller
        {
    
            public ActionResult Index(string text)
            {
                ViewBag.DisplayText = text;
                return View();
            }
        }
    

    Then the text parameter will get set when you browse to /Home?text=abc.

    For VB.NET Applications the function should be defined like this:

    Function Index(ByVal text As String) As ActionResult
             ViewBag.DisplayText = text
             Return View() 
    End Function

    Please remember to mark helpful posts as answer.

    • Marked as answer by rpalacios2003 Monday, September 1, 2014 7:46 PM
    Monday, September 1, 2014 10:06 AM
  • Hello rpalacios2003,

    For issues regarding MVC, I would suggest that you could post it to the MVC forum, there are MVC experts who would help you better.

    This forum is for issues regarding .NET Framework.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by rpalacios2003 Monday, September 1, 2014 7:46 PM
    Monday, September 1, 2014 6:21 AM
    Moderator

All replies

  • Hello rpalacios2003,

    For issues regarding MVC, I would suggest that you could post it to the MVC forum, there are MVC experts who would help you better.

    This forum is for issues regarding .NET Framework.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by rpalacios2003 Monday, September 1, 2014 7:46 PM
    Monday, September 1, 2014 6:21 AM
    Moderator
  • Are you using C# or VB.NET? It seems like you are mixing programming languages here.

    In a C# ASP.NET MVC Application you should use the following code:

        public class HomeController : Controller
        {
    
            public ActionResult Index(string text)
            {
                ViewBag.DisplayText = text;
                return View();
            }
        }
    

    Then the text parameter will get set when you browse to /Home?text=abc.

    For VB.NET Applications the function should be defined like this:

    Function Index(ByVal text As String) As ActionResult
             ViewBag.DisplayText = text
             Return View() 
    End Function

    Please remember to mark helpful posts as answer.

    • Marked as answer by rpalacios2003 Monday, September 1, 2014 7:46 PM
    Monday, September 1, 2014 10:06 AM
  • Thank you it makes sense now  so I was writing the MVC app in VB.net instead of C#.net. Thank You for you your now I understand the UI difference now.  
    Monday, September 1, 2014 8:06 PM
  • Are you using C# or VB.NET? It seems like you are mixing programming languages here.

    In a C# ASP.NET MVC Application you should use the following code:

        public class HomeController : Controller
        {
    
            public ActionResult Index(string text)
            {
                ViewBag.DisplayText = text;
                return View();
            }
        }

    Then the text parameter will get set when you browse to /Home?text=abc.

    For VB.NET Applications the function should be defined like this:

    Function Index(ByVal text As String) As ActionResult
             ViewBag.DisplayText = text
             Return View() 
    End Function

    Please remember to mark helpful posts as answer.


    Monday, September 1, 2014 8:19 PM