我有一个位于div元素中的文件上传。表单元素位于主文件中。 HasFile属性在第一次回发时始终返回false。
Asp.net代码
<div class="form-horizontal center-block" role="form" id="uploadFilesForm">
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="fileUpload" CssClass="col-md-4 control-label">Select Files</asp:Label>
<div class="col-md-8">
<asp:FileUpload runat="server" ID="fileUpload" AllowMultiple="True" />
</div>
</div>
<div class="form-group">
<asp:Label runat="server" CssClass="col-md-4 control-label"></asp:Label>
<div class="col-md-8">
<asp:Button runat="server" id="uploadButton" text="Upload" CssClass="btn btn-primary" OnClick="uploadButton_Click"/>
</div>
</div>
</div>
C#代码:
protected void Page_Load(object sender, EventArgs e)
{
Page.Form.Enctype = "multipart/form-data";
}
protected void uploadButton_Click(object sender, EventArgs e)
{
if (fileUpload.HasFile) // this returns false on first postback
{
//more code
}
}
答案 0 :(得分:0)
在您的OnInit()方法中添加以下代码:
public function organizations()
{
return $this->belongsToMany('App\Models\Organization');
}
public function broadcasts()
{
return $this->belongsToMany('App\Models\Broadcast');
}