"Object reference not set to an instance of an object" 使用绑定时
"Object reference not set to an instance of an object" while using bind
html:
<input @bind="title"/>
<div id="chat-bottom-button-right-row">
<button @onclick="(() => RunMovie(title))">Chat</button> //I'd like to use title from input
</div>
c#代码:
[Inject]
public IJSRuntime Js { get; set; }
private MovieDataDetail movieDetail = null;
string title;
private async Task RunMovie(string title)
{
movieDetail = await TmdbApi.GetAllMovieInfo(title); //Object reference not set to an instance of an object
await Js.InvokeVoidAsync("kinX").AsTask();
}
我想使用 input
的标题。
title
即使我写东西到 input
也总是 null
如果你想要双向绑定(即输入从变量填充并且变量由输入更新)然后使用:
<input @bind-value=@title />
html:
<input @bind="title"/>
<div id="chat-bottom-button-right-row">
<button @onclick="(() => RunMovie(title))">Chat</button> //I'd like to use title from input
</div>
c#代码:
[Inject]
public IJSRuntime Js { get; set; }
private MovieDataDetail movieDetail = null;
string title;
private async Task RunMovie(string title)
{
movieDetail = await TmdbApi.GetAllMovieInfo(title); //Object reference not set to an instance of an object
await Js.InvokeVoidAsync("kinX").AsTask();
}
我想使用 input
的标题。
title
即使我写东西到 input
如果你想要双向绑定(即输入从变量填充并且变量由输入更新)然后使用:
<input @bind-value=@title />