1

Hey I hope this question isn't too stupid.

How do you acess only one Value of a page. For example I have 3 variables in my cshtml file.

@{var number1 = a1;}
@{var number2 = b2;}
@{var number3 = c3;}

but if I use GET in my application downloads all of the information and I can't seperate it anymore. With this url

"http://www.myurl.com/numbers.cshtml"

The outcome is "a1b2c3".

Is it possible to acess only the value of e.g. number2? So that the outcome would be "b2"? I searched for hours and I think it has to do with the url so that I type in my application

"http://www.myurl.com/numbers.cshtml?number2"

Obviously this doesnt work. I hope you understand what I mean. I would really appreciate some usefull answers :)

Greetings

Alex

//EDIT

Hey thanks for the answers. I'm sorry if I wasn't clear enough. Basicly I want to GET data from my serverside files via Unity3D (Game Engine). I want that as soon as you log in the game downloads all the information about your profile (name, level, experience etc). The problem is, that Unity downloads the content of a whole URL. I can't acess any values or variables. It's output is pure text. Now of course I could write for each text field its own script but I prefer to have certain groups in one file. Basicly I download the values from my DB and then to Unity3D. As it downloads everything I need to download only the ones I need right now. For example I want to download only the players name but as it's in the same file I need to tell unity somehow that I only want a specific variable. I thought this would be possible by using a modified URL. If I'm wrong and this is total nonsense I'm very sorry.

//EDIT2:

The Code inside the application:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public string url = "http://localhost:19206/ListProducts.cshtml";

 IEnumerator Start()
    {
        WWW www = new WWW(url);
        yield return www;
        guiText.text = www.text;
    }

Unfortunatly something like www.number1.text didn't work. Thank you so much again!

//EDIT3

and finaly my simple and basic code of my asp.net razor file. There is no DB implementation yet but I guess that has nothing to do with it.

@{ var experience = 3532; }
@{ var playerName = "Player1"; }

Your current experience is: @experience
Your Playername is: @playerName
8
  • You use the @ prefix, but I'm not 100% sure how to do it inside a string like that... Commented May 24, 2012 at 1:19
  • 1
    Alex, it's really not clear what you want here. Do you want a view to display one of three different numbers based on a URL parameter? If so, the proper place to do the logic is in the controller, not the view. Please try to be more clear about what you're trying to do and/or include some more of your code. Commented May 24, 2012 at 1:21
  • You are not showing how you are consuming those variables, which is really the most important part of your question. Show us the code that uses them. Commented May 24, 2012 at 1:27
  • "@{var number1 = a1;}" is just definition of the variable, but not rendering portion. Can you show part of the view where you render them? Commented May 24, 2012 at 1:41
  • @AlexanderBadak, you still haven't shown us your .cshtml file that acutally uses number1, number2, etc. Commented May 24, 2012 at 1:50

1 Answer 1

1

Consider simply returning JsonResult from the action instead of coming up with custom view.

 return JsonResult({number1=42, text1="bla", number2=7});

And on JavaScript side you'll get {number1:42, text1:"bla", number2:7} which is very JavaScript friendly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.