小编Shi*_*han的帖子

在Asp.Net mvc 4中使用AJAX提交表单

我正在尝试学习asp.net,到目前为止我可以加载其他页面内容而无需刷新使用Ajax.Actionlink,AjaxOptions()但我无法弄清楚如何在提交表单时使用ajax.我做了很多谷歌搜索,但找不到合适的解决方案.这是我的代码,

控制器页面

namespace CrudMvc.Controllers
{
public class HomeController : Controller
{
    sampleDBEntities db = new sampleDBEntities(); 
    //
    // GET: /Home/

    public ActionResult Index()
    {
        return View(db.myTables.ToList());
    }

    public PartialViewResult Details(int id = 0)
    {
        myTable Table = db.myTables.Find(id);
        return PartialView(Table);
    }

    [HttpGet]
    public PartialViewResult Create()
    {
        return PartialView();
    }

    [HttpPost]
    public ActionResult Create(myTable table)
    {
        if (ModelState.IsValid)
        {
            db.myTables.Add(table);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(table);
    }

    protected override void Dispose(bool disposing)
    {
        db.Dispose();
        base.Dispose(disposing);
    }
} …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net ajax asp.net-mvc jquery

28
推荐指数
1
解决办法
9万
查看次数

Google中的idpiframe_initialization_failed从Localhost登录

我正在尝试按照此链接创建一个谷歌登录按钮.到目前为止,帐户选择对话框即将到来,但之后我在控制台中看不到任何结果.相反,我在页面加载时收到此错误,

"idpiframe_initialization_failed", details: "Not a valid origin for the client: http://localhos…itelist this origin for your project's client ID."
details: "Not a valid origin for the client: http://localhost has not been whitelisted for client ID 386404527657-q4ss06np5g27dllq5ds7aif42udkh7e5.apps.googleusercontent.com. Please go to https://console.developers.google.com/ and whitelist this origin for your project's client ID."
Run Code Online (Sandbox Code Playgroud)

这是代码,

<html lang="en">
  <head>
    <meta name="google-signin-scope" content="profile email">
    <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script> …
Run Code Online (Sandbox Code Playgroud)

javascript google-api google-oauth google-plus-signin google-signin

13
推荐指数
6
解决办法
1万
查看次数

在asp.net mvc中一次更新多个记录

我正在尝试使用asp.net mvc 4&EF6我想要一次更新多行的网站.但由于某种原因,它不起作用,我得到这样的错误,

System.NullReferenceException:未将对象引用设置为对象的实例

这是我的代码,

调节器

[HttpPost]
    public ActionResult MakeDue(List<BillCheck> BillLists)
    {
        if (Session["username"] != null)
        {
            if (ModelState.IsValid)
            {
                foreach (var BillId in BillLists)
                {
                    var getDue = db.BillChecks.Where(p => p.id == BillId.id).FirstOrDefault();
                    getDue.due = BillId.due;
                }
                db.SaveChanges();
                return RedirectToAction("Success");
            }
            else
            {
                return RedirectToAction("Failed");
            }
        }
        else
        {
            return RedirectToAction("Login");
        }
    }
Run Code Online (Sandbox Code Playgroud)

视图

@using (Html.BeginForm("MakeDue", "Home"))
{
    @Html.ValidationSummary(true)
    @foreach(var item in Model.DueList)
    {
        @Html.HiddenFor(modelItem => item.id)
        <tr>
            <td>@Html.DisplayFor(modelItem => item.flat)</td>
            <td>@Html.DisplayFor(modelItem => item.name)</td>
            <td>@Html.TextBoxFor(modelItem …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc

8
推荐指数
1
解决办法
2万
查看次数

在jquery中悬停时显示图像上的链接

我正在使用Bootstrap 3jQuery 1.9.1创建一个网站,其中个人资料图片显示在<li>标签中.当我将鼠标悬停在图像上时,我想显示"更新图像"的链接.到目前为止,我已经设法在悬停时淡出图像但是我无法在悬停在图像上时显示链接或文本.这是我的代码,

JQUERY

$(function () {
    $(".img-profile").hover(
        function () {
            $(this).fadeTo(200, 0.45);
        },
        function () {
            $(this).fadeTo(200, 1);
        });
});
Run Code Online (Sandbox Code Playgroud)

CSS

.img-profile {
    margin-top: 10px;
    width: 200px;
    height: 250px;
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div class="navbar-default sidebar" role="navigation">
    <div class="sidebar-nav navbar-collapse">
        <ul class="nav" id="side-menu">
            <li>
                <img class="img-responsive img-rounded img-profile" src="myimage.png" alt="profile_pic" />
            </li>
        </ul>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我搜索了其他来源,但没有一个有效,因为它会破坏我自己的CSS样式.如何在悬停时在图像中间显示链接?急需这个帮助!谢谢.

html javascript css jquery twitter-bootstrap

7
推荐指数
1
解决办法
1644
查看次数

使用linqtoexcel从excel文件中获取所有值

linqtoexcel在我的asp.net mvc 4项目中使用它来读取 Excel 文件并从那里获取所有值。但我只得到最后一行的值。这是我的代码,

控制器

    public ActionResult ExcelRead()
    {
        string pathToExcelFile = ""
        + @"C:\MyFolder\ProjectFolder\sample.xlsx";

        string sheetName = "Sheet1";

        var excelFile = new ExcelQueryFactory(pathToExcelFile);
        var getData = from a in excelFile.Worksheet(sheetName) select a;

        foreach (var a in getData)
        {
            string getInfo = "Name: "+ a["Name"] +"; Amount: "+ a["Amount"] +">>   ";
            ViewBag.excelRead = getInfo;
        }
        return View();
    }
Run Code Online (Sandbox Code Playgroud)

看法

@ViewBag.excelRead
Run Code Online (Sandbox Code Playgroud)

如何获取所有行的值?非常需要这个帮助!谢谢。

c# asp.net-mvc excel linq-to-excel

4
推荐指数
1
解决办法
1万
查看次数

在asp.net mvc中一次编辑多个记录

我正在尝试使用asp.net mvc 4&开发一个网站EF6,我希望同时更新多个记录.但只有一个数据正在更新和休息仍然是相同的.这是我的代码,

调节器

var resetInfo = db.myInfoes.Where(p => p.id == ClId).FirstOrDefault();
if (resetInfo != null)
{
    resetInfo.id = 0;
    resetInfo.name = "N/A";
    resetInfo.phone = "N/A"
    db.SaveChanges();
    TempData["success"] = "Information Updated Successfully!";
    return RedirectToAction("Index");
}
else
{
    TempData["fail"] = "Error! Information Update Failed!";
    return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)

我在这里做错了吗?如何一次更新与所有ID对应的记录?非常需要这个帮助.谢谢.

c# asp.net asp.net-mvc

0
推荐指数
1
解决办法
837
查看次数