MVC를 처음 사용합니다. 나는 하나의 프로젝트를 만들기 시작했고 하나의 큰 문제에 직면했다. pls 이걸 도와 줘. 설명 : 나는이 하나 actionlink 및로드 한 부분보기아약스 호출 부분보기로드
@model List<MuthuTag.Models.LoadPostModel>
@{
ViewBag.Title = "LoadPost";
}
@Html.ActionLink("Add New Post","Post","Home")
<h2>LoadPost</h2>
<div>
<table>
@foreach (var Item in Model)
{
<tr>
<td>
@Item.TagId
</td>
<td>
@Item.TagTitle
</td>
<td>@Item.TagContent</td>
</tr>
}
</table>
</div>
와 전망이 유는 새 게시물 액션 추가 링크를 클릭 할 수 있습니다 그래서 병이 부하 다른보기 컨트롤러 코드
public ActionResult Post()
{
return View();
}
그것을 병이로드
@model MuthuTag.Models.LoadPostModel
@{
ViewBag.Title = "Add New Post";
}
<script src="~/Content/jquery-1.8.3-min.js"></script>
<h2>Post</h2>
<link href="~/Content/magicsuggest-1.3.1.css" rel="stylesheet" />
<script src="~/Content/magicsuggest-1.3.1.js"></script>
<div id="Post">
<table>
<tr>
<td>
@Html.LabelFor(m => m.TagId)
</td>
<td>
@Html.TextBoxFor(m => m.TagId)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.TagTitle)
</td>
<td>
@Html.TextAreaFor(m => m.TagTitle)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.TagContent)
</td>
<td>
@Html.TextAreaFor(m => m.TagContent)
</td>
</tr>
</table>
<div id="ms-tpl"></div>
<script type="text/javascript">
$('#ms-tpl').magicSuggest({
width: 590,
highlight: true,
data: [{
id: 0,
name: "C#",
desc: "Server Code for all Web Applications in Microsoft Products",
//image: "images/panda.png"
}, {
id: 1,
name: "ASP.Net",
desc: "Active Server Page that Holds Web Tech.",
// image: "images/butterfly.png"
}, {
id: 2,
name: "Silverlight",
desc: "Sliverlight is the Microsoft Product with Great UI Design Sets",
// image: "images/dolphin.png"
}, {
id: 3,
name: "MVC4",
desc: "Latest of all Microsoft Web Tech",
// image: "images/elephant.png"
}, {
id: 4,
name: "PHP",
desc: "Light Weight Server Page",
//image: "images/hippo.png"
}, {
id: 5,
name: "Sql",
desc: "Default Database Provider for Microsoft technologies",
//image: "images/turtle.png"
}],
renderer: function (v) {
return '<div>' +
'<div style="float:left;"><img src="' + v.image + '"/></div>' +
'<div style="padding-left: 85px;">' +
'<div style="padding-top: 20px;font-style:bold;font-size:120%;color:#333">' + v.name + '</div>' +
'<div style="color: #999">' + v.desc + '</div>' +
'</div>' +
'</div><div style="clear:both;"></div>';
}
});
</script>
<input type="button" value="click" id="click"/>
<input type="button" value="Save" id="Register" />
</div>
<div id="bind"></div>
<script type="text/javascript">
var jsonData = [];
var ms1 = $('#ms-tpl').magicSuggest({
data: jsonData,
sortOrder: 'name',
maxResults: false
});
$('#Register').click(function() {
debugger;
var dataplus = ms1.getValue();
var tagid = document.getElementById('TagId').value;
var tagtitle = document.getElementById('TagTitle').value;
var tagcontent = document.getElementById('TagContent').value;
$.ajax({
url: '@Url.Action("GetPost")' + '?tagid=' + tagid + '&tagtitle=' + tagtitle + '&tagcontent=' + tagcontent + '&dataplus=' + dataplus,
type: 'POST',
cache: false,
success: function (data) {
}
});
});
$('#click').click(function() {
debugger;
alert(ms1.getValue());
});
</script>
[HttpPost]
public ActionResult GetPost(Profile model)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
string tagid = Request.Params["tagid"];
string tagtitle = Request.Params["tagtitle"];
string tagcontent = Request.Params["tagcontent"];
SqlCommand cmd = new SqlCommand("CreatePostDetail", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@TagId", tagid);
cmd.Parameters.AddWithValue("@TagContent", tagcontent);
cmd.Parameters.AddWithValue("@TagTitle", tagtitle);
//string name = Session["UserName"].ToString();
string name = "123";
cmd.Parameters.AddWithValue("@UserName", name);
cmd.ExecuteNonQuery();
con.Close();
return View("Index");
}
때문에 사용자가 클릭하면 뷰는 승 버튼 저장 병은 메인 페이지에 추가 된 내용 병 디스플레이는하지만 혼자 포스트보기에 남아 있지만 데이터가 데이터베이스에 저장하도록 내가 인덱스를 반환 컨트롤러
[HttpPost]
public ActionResult GetPost(Profile model)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
string tagid = Request.Params["tagid"];
string tagtitle = Request.Params["tagtitle"];
string tagcontent = Request.Params["tagcontent"];
SqlCommand cmd = new SqlCommand("CreatePostDetail", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@TagId", tagid);
cmd.Parameters.AddWithValue("@TagContent", tagcontent);
cmd.Parameters.AddWithValue("@TagTitle", tagtitle);
//string name = Session["UserName"].ToString();
string name = "123";
cmd.Parameters.AddWithValue("@UserName", name);
cmd.ExecuteNonQuery();
con.Close();
return View("Index");
}
로 이동합니다. (간단한 방법 actionlink (post) -> 홈 페이지를 다시로드하는 새로운 뷰를로드하지만 포스트 뷰에 남아 있음).
의 내가 시도하지만 동일에 남아 있습니다. – user3534449