0

I can display two Twitter boxes next to each other like this, using the Web Helpers package in a Razor 2 asp.net website.

<div id="dynaMashTab-Twitter" >
    <span id="spanProfile" style="display: inline-block;vertical-align:top">@Twitter.Profile("jQuery")</span><span id="spanSearch"><span style="display: inline-block;vertical-align:top">@Twitter.Search("jQuery")</span>
</div>

...but I want to be able to dynamically change from "jQuery" to whatever. I've tried this way:

HTML:

<label for="inputQuery" style="display: inline-block;">Enter something, quick!</label>
<input type="text" name="inputQuery" id="inputQuery" placeholder="Enter something already" autofocus style="display: inline-block;" />

jQuery:

$(document).ready(function () {

    $("#inputQuery").keyup(function(e) {
        if (e.keyCode == 13) {
            var inputQueryText = $("#inputQuery").val();
            $("#spanProfile").html(@Twitter.Profile(inputQueryText));
            $("#spanSearch").html(@Twitter.Search(inputQueryText));
        }
    });
 });

...but I get, "The name 'inputQueryText' does not exist in the current context"

I realize that, even if this works, what I'm assigning to #spanProfile and #spanSearch won't be formatted as before, but I'm starting with baby steps with this and have already taken a bit of a tumble.

4

1 回答 1

0

这是可以做到的:

剃刀:

var searchTermHTML = "jquery";
if (IsPost)
{
    searchTermHTML = Request["inputText"];
}

HTML:

    <form method="POST" action="/">
        <label for="inputText" style="display: inline-block;">Hunh?</label>
        <input type="text" name="inputText" id="inputText" placeholder="Enter at your own risk" value="@Request["inputText"]" autofocus style="display: inline-block;" />
        <input type="Submit" name="btnSubmit" id="btnSubmit" value="Make it sort of funky" style="display: inline-block;" />
    </form>

. . .

<div id="duckbilledPlatypusTab-Twitter">
    <span id="spanProfile" style="display: inline-block; vertical-align: top">@Twitter.Profile(searchTermHTML, numberOfTweets: 42, scrollBar: true, avatars: true)</span>
    <span id="spanSearch" style="display: inline-block; vertical-align: top">@Twitter.Search(searchTermHTML, scrollBar: true)</span>
</div>
于 2013-05-23T03:55:42.223 回答