开发者

WebMatrix UrlData collection not getting filled in MVC

开发者 https://www.devze.com 2023-02-14 14:10 出处:网络
I have an MVC 3 application which employs WebMatrix in one of its pages. I have something like thi开发者_开发百科s in the page:

I have an MVC 3 application which employs WebMatrix in one of its pages.

I have something like thi开发者_开发百科s in the page:

string s1 = UrlData[0];
var query = "select * from test where id = " + UrlData[1];
// Open the database of the service delivery
var dataBase = Database.Open("connection_string");
var results = database.Query(query);

There is an MVC Dropdownlist in the page and in the onchange event of this dropdownlist i am submitting the MVC form. It goes to the controller method which has this dropdownlist value as the parameter and after some operations is redirected back to the same page using RedirectToAction().

But, the UrlData collection does not have any values. Could some one help me out with this?

Thanks Nidhin


UrlData is sorta like a Querystring with the execption that each value is located by position not by name. So if you where to have Url like http://localhost:6324/A/B/C/D in you Default.cshtml page and you did the following code:

<p>Total number of items in UrlData: @UrlData.Count</p>
<ul>
    @for(var i = 0; i < UrlData.Count; i++){
        <li>UrlData[@i]: @UrlData[i]</li>
    }
</ul>

the output would look like

    UrlData[0] : A
    UrlData[1] : B
    UrlData[2] : C
    UrlData[3] : D

To clarify even further here is a "fantastic" article on the subject UrlData

0

精彩评论

暂无评论...
验证码 换一张
取 消