我在创建视图上创建了一个模态。我有三个按钮 - &#39; 添加条件&#39;无条件&#39; 和&#39;取消&#39; 。单击每个按钮时,我希望它执行操作。到目前为止,唯一有效的按钮是“取消”按钮。按钮,因为我使用<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- your content layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:elevation="0dp" />
</android.support.design.widget.AppBarLayout>
<!--content of account activity-->
<ScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_setup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bla"
android:id="@+id/accountnamefield"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recently Match"
android:id="@+id/recentMatchTitle"
android:textSize="18sp"
android:layout_below="@+id/accountnamefield"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
而不是我的控制器中的代码。我的问题是如何访问控制器中的data-dismiss="modal"
。我尝试了以下Modal代码和相应的Ajax代码。
模态:
ActionResult
的Ajax:
<button type="button" id="confirmItem" data-target="#confirmModal" data-toggle="modal" @*data-id="#AddConditions">Create</button>
<body>
<br/>
<div class="modal fade" id="confirmModal" tabindex="-1" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dissmiss="modal" aria-hidden="true">@*×*@</button>
<h4 class="modal-title">Confirm</h4>
</div>
<div class="modal-body">
<p>Confirm that Requested Burn Conditions should be added.</p>
</div>
<div class="modal-footer">
<button id="btnAddConditions" type="button" class="btn btn-primary">Add Conditions</button>
<button id="btnNoConditions" type="button" class="btn btn-primary" >No Conditions</button>
<button data-dismiss="modal" type="button" class="btn btn-default">Cancel</button>
</div>
</div>
</div>
</div>
</body>
答案 0 :(得分:0)
尝试使用以下代码从MVC中的ajax调用控制器操作。
var checkConditon = $(".confirmItem").data('id');
var url = '@Url.Action("AddCondition", "RequestedBurns")';
$.ajax({
url: url,
type: "POST",
data: { checkConditon : checkConditon },
success: function (data) {
alert('success');
},
error: function (error) {
alert("Error Ajax not working: " + error);
}
});